Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 115 - 2620_Birla Open Mind C-8
P. 115

    Program 3: To print your name nine times using for loop with range() function
                         Program3.py

                      File  Edit  Format   Run   Options   Window    Help

                      #Program to print your name 9 times using the for loop

                      name = input ('Enter your name: ')
                      for i in range(0, 9):
                          print(name)

                     On running the above program, we get the following output:

                         Output
                      Enter your name: Sambhav
                      Sambhav
                      Sambhav
                      Sambhav
                      Sambhav
                      Sambhav
                      Sambhav
                      Sambhav
                      Sambhav
                      Sambhav

                     Program 4: To print multiplication table of an input number
                                                                                                    Output

                          Program4.py                                                            Enter a number: 8
                                                                                                 8 X 1 = 8
                       File  Edit  Format   Run   Options   Window     Help                      8 X 2 = 16
                                                                                                 8 X 3 = 24
                       #Program to print multiplication table of a number                        8 X 4 = 32
                                                                                                 8 X 5 = 40
                       num = int (input('Enter a number: '))                                     8 X 6 = 48
                                                                                                 8 X 7 = 56
                       for i in range (1,11):                                                    8 X 8 = 64
                       #printing the table                                                       8 X 9 = 72
                           print(num, 'X', i, '=', num*i)                                        8 X 10 = 80

                          THE WHILE STATEMENT

                     The while statement executes a set of statements repeatedly, until
                     the logical expression evaluates to true. When the condition becomes             Test Expression  False
                     false, the control comes out of the loop. The syntax of while statement
                     is given below.                                                                          True
                     while (test expression):
                                                                                                 Execute the while statement
                         Statements
                         increment/decrement
                                                                                                                      Exit loop

                                                                                                       #Loops in Python 113

| 110 111 112 113 114 115 116 117 118 119 120 |