Basic HTML Version

|  | Table of Contents |  | View Full Version

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

    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.

                                                 Program11.py
                                              File  Edit  Format   Run   Options   Window    Help

                                              #Program to create star pattern

                                              for i in range(10, 0, -1):
                                                  print("*"*i)

                                                       Output

                                                    **********
                                                    *********
                                                    ********
                                                    *******
                                                    ******
                                                    *****
                                                    ****
                                                    ***
                                                    **
                                                    *

                              NASA’s reusable space shuttle in the 1970s had less code than our phones today.

                                                                                                       #Loops in Python 119

| 116 117 118 119 120 121 122 123 124 125 126 |