Page 148 - TP_Prime_V2.2_Class8
P. 148

Program 9: To print the cube of all the numbers between 0 and 12 with an else statement.

                      Program9.py
                   File  Edit  Format    Run   Options   Window    Help

                   a=0
                   b=12
                   while a<=b:
           Prime (Ver. 2.2)-VIII      a=a+1
                       c=(a**3)
                       print(c)


                   else:
                       print("end of loop reached")




                      Output

                   0
                   1
          146      8

                   27
                   64
                   125
                   216
                   343
                   512
                   729
                   1000
                   1331
                   1728
                   end of loop reached



                                                      Using loop with else statement
                  In the  above program,  the  else  statement is                               Python does not

                  executed only after the while condition became                  Fun           have do-while loop.
                  false.                                                          Fact!




                        Warm
                                                                                                   21 st
                        Up!        Write ‘T’ for true and ‘F’ for false.                         Century   #Information Literacy
                                                                                                  Skills
                                   1.   The while loop is used when we know the final value of

                                      the condition.                                                     __________
                                   2.   There are three membership operators in Python.                  __________
                                   3.   The range( ) function is used with for loop to generate a

                                       list of numbers.                                                  __________
   143   144   145   146   147   148   149   150   151   152   153