Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 150 - 2632_CodeMind
P. 150

    You will get the following output:

                         Output

                      3
                      33
                      333
                      3333
                      33333
                      333333
                      3333333
                      33333333
                      333333333

                      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)                                           *

                                                                                                      Loops in Python  149

| 145 146 147 148 149 150 151 152 153 154 155 |