Page 124 - TP_Play_V2.1_class8
P. 124

"Imagine, you possess the power of jump statement, allowing you to leap to
                                    any part of the universe. Where would you jump to and what quests or missions
                                    would you undertake in each dimension?"




                   Program 10: To add first five natural numbers.



                      Program10.py
                   File  Edit  Format   Run    Options   Window    Help

                   #Program to add first five natural numbers

                   sum = 0
                   a = 1
                   while (a <= 5):
                       sum += a
                       a += 1
                   print('The sum of first five natural number is', sum)





                  You will get the following output:

                      Output

                   The sum of first five natural number is 15





                   Program 11: To print the pattern of stars in decreasing order in the form of triangle.

                  **********
                  *********
                  ********
                  *******
                  ******
                  *****
                  ****
                  ***                                                            Output
                  **
                                                                              **********
                  *
                                                                              *********
                      Program11.py                                            ********
                                                                              *******
                   File  Edit  Format    Run   Options   Window    Help       ******
                                                                              *****
                   #Program to create star pattern
                                                                              ****
                                                                              ***
                   for i in range(10, 0, -1):
                                                                              **
                       print("*"*i)                                           *




                  122       Play (Ver. 2.1)-VIII
   119   120   121   122   123   124   125   126   127   128   129