Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 76 - 2607_Traclpad_Pro_5.1_flipbook_C8
P. 76

    SOME MORE PROGRAMS

                     Program 7: To create a number pattern using for loop.

                         Program7.py

                      File  Edit  Format   Run    Options   Window    Help

                      #Program to create number pattern using for loop

                      for i in range(1,5):
                          print('3' * i)

                     You will get the following output:

                         Output

                      3
                      33
                      333
                      3333

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

                         Program8.py

                      File  Edit  Format   Run    Options   Window    Help

                      #Program to create star pattern

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

                     You will get the following output:

                         Output

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

                                                                                                   Iterations in Python  75

| 71 72 73 74 75 76 77 78 79 80 81 |