Page 77 - Code Craft Computer-8
P. 77

The general syntax of using the range() function is given below.

            range(n): 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): Generates a set of whole numbers starting from 'start' to 'stop-1'.

            Example: range(3, 9) is equivalent to {4, 5, 6, 7, 8}.
            Range (start, stop, step_size): By default, the value of the step_size = 1 and numbers generated
            with a difference of 1. However, we can generate numbers by specifying the value of step_size

            accroding to our requirement.
            Example: range(1, 14, 2) is equivalent to [1, 3, 5, 7, 9, 11, 13].

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



















            On running the above program, we get the following output:























            Program 6: To print multiplication table of an input number.




















                                                                 77
   72   73   74   75   76   77   78   79   80   81   82