Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 145 - 2632_CodeMind
P. 145

    Program 2: To print a pattern using for loop.

                                                                                              Output
                                                                                           *
                                                                                           **
                                                                                           ***
                            Program2.py                                                    ****
                         File  Edit   Format     Run    Options    Window     Help         *****
                                                                                           ******
                         #Program to create a pattern using for loop                       *******
                         for a in range(1,10):                                             ********
                             print('*'*a)                                                  *********

                       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, 9):
                           print(name)

                      You will get the following output:

                          Output

                       Enter your name: Sambhav
                       Sambhav
                       Sambhav
                       Sambhav
                       Sambhav
                       Sambhav
                       Sambhav
                       Sambhav
                       Sambhav
                       Sambhav

                      144   Premium Edition-VIII

| 140 141 142 143 144 145 146 147 148 149 150 |