Lesson 5: range( ) Function
Challenge focus: 31 - 40
Coding Concepts : range( )
December 2023
Banana Tales I
Key stage III
Class VII
LESSON OVERVIEW
CODING CONCEPT | Range | |||||||||
CHALLENGE | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
SUB CONCEPTS |
| |||||||||
RESOURCES | Lesson Plan 25 Range |
December 2023
Banana Tales I
Key stage III
Class VII
Lesson Objectives
At the end of the lesson, each child should be able to:
December 2023
Banana Tales I
Key stage III
Class VII
Understanding range( ) Function
range([start], [stop], [step]) |
December 2023
Banana Tales I
Key stage III
Class VII
Example
Usages | Description | Sequenced Created | Comments |
range(4) | range() function with one argument | 0, 1, 2, 3 | start = 0, stop = 4, step = 1 |
range( 2, 7) | range() function with two arguments | 2, 3, 4, 5, 6 | start = 2, stop = 7, step = 1 |
range(2, 11, 2) | range() function with three arguments | 2, 4, 6, 8, 10 | start = 2, stop = 11, step = 2 |
December 2023
Banana Tales I
Key stage III
Class VII
The for Loop with range( ) Function
1 2 | for loop_variable in range([start], [stop], [step]): #Your code here |
December 2023
Banana Tales I
Key stage III
Class VII
Example 1
Write a Python code in your notebook to display the sequence of number from 1 to 5 using the range( ) function.
1 2 | for x in range(1,6,1): print(x) |
start = 1
stop = 5+1 = 6
step = 1
December 2023
Banana Tales I
Key stage III
Class VII
Concept explanation of above example
Example 1 (Cont.)
iteration | x | Condition ( x < 6 ) | print(x) |
1st | 1 | 1 < 6 = True | 1 |
2nd | 2 | 2 < 6 = True | 2 |
3rd | 3 | 3 < 6 = True | 3 |
4th | 4 | 4 < 6 = True | 4 |
5th | 5 | 5 < 6 = True | 5 |
6th | 6 | 6 < 6 = False | The condition is false and it will exit out of the loop |
The following table shows the iteration concept of the for loop from previous slide.
1 2 | for x in range(1,6,1): print(x) |
1 2 3 4 5 | # Output 1 2 3 4 5 |
December 2023
Banana Tales I
Key stage III
Class VII
Demo 1
Study the given challenge and write a code using the range( ) function to reach the banana to the monkey(challenge 31).
December 2023
Banana Tales I
Key stage III
Class VII
Demo 1 Solution
December 2023
Banana Tales I
Key stage III
Class VII
Demo 1
This table shows how the giraffes’ height get changed as per the value of index variable as the for loop iteration happens.
Iteration | Value of index | Giraffes’ height |
1st | index = 0 | giraffes[0].height = 10 |
2nd | index = 1 | giraffes[1].height = 10 |
3rd | index = 2 | giraffes[2].height = 10 |
4th | index = 3 | giraffes[3].height = 10 |
5th | index = 4 | giraffes[4].height = 10 |
6th | index = 5 | giraffes[5].height = 10 |
December 2023
Banana Tales I
Key stage III
Class VII
Activity 1
Study the challenge given below and rewrite the codes using the range( ) function to make the banana reach to the monkey in your notebook.(challenge 32).
December 2023
Banana Tales I
Key stage III
Class VII
Activity 1 Solution
1 2 | for i in range(4): snakes[i].length = 3 |
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2 Solution
33
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2 Solution
34
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2 Solution
35
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2 Solution
36
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2 Solution
37
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2 Solution
38
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2 Solution
39
December 2023
Banana Tales I
Key stage III
Class VII
Activity 2 Solution
40
December 2023
Banana Tales I
Key stage III
Class VII
Key Points
December 2023
Banana Tales I
Key stage III
Class VII