Page 68 - Code & Click - 8
P. 68

The Start_val represents the initial value, and the End_val represents the final value. The Step_val
            represents the value by which the counter variable is incremented or decremented. The Start_val
            and the Step_val are optional values but the End_val is compulsory. The default value for the Start_
            val is 0 and Step_val is 1. The counter variable begins with the initial value, increases the value by the
            step value until it reaches a value 1 less than the value specified in the range function.

            Consider the following examples of range function:
               •  The statement range(5) will create a list of numbers from 0 to 4, i.e., 0, 1, 2, 3, 4
               •  The statement range (1,10) will create a list of numbers from 1 to 9, i.e., 1, 2, 3, 4, 5, 6, 7, 8, 9

               •  The statement range (1, 10, 2) will create a list of numbers from 1 to 9 with a gap of 2 between
                  two consecutive numbers, i.e., 1, 3, 5, 7, 9
                                                                                                 Experiential Learning
              Lab Activity 3
             To display all even numbers between 1 and 25.
             1. Type the code as shown in the image in the Python Editor.


















             2. Press the F5 key to execute the code. Sample output of the program is given.


                                                                                                 Experiential Learning
              Lab Activity 4

             To accept a number from the user and display the sum of all numbers from 1 to the entered number.
             1. Type the code as shown in the image in the Python Editor.









             2. Press the F5 key to execute the code. Sample output of the program is given below.
















            66
   63   64   65   66   67   68   69   70   71   72   73