Page 102 - TP_Play_V2.2_Class8
P. 102

You will get the following output:
                   Output

                Monday
                Tuesday
                Wednesday
                Thursday
                Friday
                Saturday
                Sunday


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





              Using the range() Function

              The range() function is an in-built function of Python. This function generates a list which is a sequence
              type. A sequence is a succession of values bound together by a single name. The range() function is
              used in the for loop to iterate over the numbers.
              The general syntax of using the range() function is given below.

                  range(n): It generates a set of whole numbers starting from 0 to (n–1).

                 Example: range(6) is equivalent to [0, 1, 2, 3, 4, 5].
                   range(start,  stop):  It  generates a set of  whole
                 numbers starting from ‘start’ to ‘stop–1’.                                   Hintbot
                 Example: range(3, 9) is equivalent to [3, 4, 5, 6, 7, 8].  To generate series in a reverse order: start

                   range(start, stop,  step_size):  By  default,  the      must be greater than stop, and step size
                                                                                     should be negative.
                 value  of  the  step_size  =  1  and  numbers  are
                 generated with a difference of 1. However, we
                 can generate numbers by specifying the value of step_size according to our requirement.
                  Example: range(1, 14, 2) is equivalent to [1, 3, 5, 7, 9,11,13].











                  100  Plus (Ver. 4.0)-VIII
   97   98   99   100   101   102   103   104   105   106   107