Page 46 - tp_Modula_v2.0
P. 46

Program 2: To print a pattern using for loop.

















                      Program2.py
                   File  Edit  Format   Run   Options  Window    Help

                   # program to a pattern using for loop


                   for a in range (1,10):
                       print("*"*a)





                  On running the above program, you will get the following output:
                      Output

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



                  Program 3: To print your name nine times using for loop with range( ) function.

                      Program3.py
                   File  Edit  Format   Run   Options  Window    Help

                   # program to print your name 9 times using the for loop


                   name = input('Enter your name: ')
                   for i in range (0,5):
                       print(name)











                   44     Touchpad MODULAR (Version 2.0)
   41   42   43   44   45   46   47   48   49   50   51