Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 123 - 2615_KEC
P. 123

    SOME MORE PROGRAMS

                     Program 20: To print numbers from 1 to 5.
                                                                                           Output

                         Program20.py                                                    1
                                                                                         2
                      File  Edit  Format    Run   Options   Window    Help
                                                                                         3
                      for i in range(1, 6):
                                                                                         4
                          print(i)
                                                                                         5

                     Program 21: To print the message Good Morning 3 times.

                         Program21.py

                      File  Edit  Format  Run    Options  Window    Help           Output
                                                                                Good Morning
                      for i in range(3):
                                                                                Good Morning
                          print("Good Morning")
                                                                                Good Morning

                     Program 22: To print the numbers count down from 5 to 1.
                                                                                   Output
                         Program22.py
                                                                                5
                      File  Edit  Format  Run    Options  Window    Help        4
                                                                                3
                      for i in range(5, 0, –1):
                                                                                2
                          print(i)
                                                                                1

                     Program 23: To prints the message Bell Ringing five times.

                                                                                   Output
                         Program23.py
                                                                                Bell Ringing
                      File  Edit  Format  Run    Options  Window    Help        Bell Ringing
                                                                                Bell Ringing
                      for i in range(5):
                                                                                Bell Ringing
                          print("Bell Ringing")
                                                                                Bell Ringing

                     Program 24: To display all the characters of your name.

                         Program24.py
                      File  Edit  Format  Run    Options  Window    Help
                                                                                   Output
                      name = "Sia"
                                                                                S
                      for letter in name:
                                                                                i
                          print(letter)                                         a

                                                                                            Control Structures in Python  121

| 118 119 120 121 122 123 124 125 126 127 128 |