Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 83 - 2611_SmartGPT Pro V(5.0) C-8
P. 83

    Program 1: To print odd numbers till 10 using start, stop and step values of a range function.

                         Program1.py                                               Output
                      File  Edit  Format  Run    Options  Window    Help        1
                                                                                3
                      for i in range (1,10,2):
                                                                                5
                          print(i)
                                                                                7
                                                                                9

                     Program 2: To print a selected range of numbers with start and stop values.

                         Program2.py                                               Output

                      File  Edit  Format   Run   Options  Window    Help        3
                                                                                4
                      for i in range (3,7):
                                                                                5
                          print(i)
                                                                                6

                     Program 3: To print whole numbers from 0 to 4 using only stop value.

                         Program3.py                                               Output
                      File  Edit  Format   Run   Options  Window    Help        0
                                                                                1
                      for i in range (5):
                                                                                2
                          print(i)
                                                                                3
                                                                                4

                     Program 4: To print a pattern using for loop.

                                 *

                                 **
                                 ***

                                 ****

                         Program4.py                                               Output
                      File  Edit  Format  Run    Options  Window    Help        *
                                                                                **
                      for i in range (1,5):
                                                                                ***
                          print("*"*i)
                                                                                ****

                     Here, * operator repeats the string for a given number of times.

                                                                                                      Loops in Python  81

| 78 79 80 81 82 83 84 85 86 87 88 |