Page 198 - AI Ver 3.0 Class 11
P. 198

Output:
                   20
                   21
                   22
                   23
                   24
                3.   range(start, stop, step): This generates a sequence of number beginning with start and going up to stop, but
                   not including the specified stop value. It allows you to specify the increment or decrement value by adding or
                   subtracting the value.

                   Program 22: To demonstrate the use of a range () with start, stop, and step values

                   for i in range(25, 5, -5):
                        print(i)
                   Output:

                   25
                   20
                   15
                   10

                             Reboot


                    1.  Fill in the blanks:

                       a.   The  ………………………. statement is used to execute a block of code  when  the  condition  in the  if
                          statement is False.

                       b.  The ………………………. loop executes continuously until the condition is False.
                       c.  The ………………………. function generates a sequence of numbers.
                    2.  Give the output of the following code:
                        x = 5
                        while x > 0:
                            print(x, end=" ")
                            x -= 2




              Jump Statements
              Sometimes, there is a situation when the control of the program needs to be transferred out of the loop body, even if
              all the values of the iterations of the loop have not been completed. For this purpose, jumping statements are used in
              Python. Python offers different jumping statements—break and continue, which are used within the loop.

              The break Statement
              The break is a keyword in Python which is used for bringing the program control out of the loop. The break statement
              halts the execution of a loop and the program flow switches to the statement after the loop. A single break statement
              will break out of only one loop.
              The syntax of the break statement is as follows:

                   #loop statement
                        break

                    196     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   193   194   195   196   197   198   199   200   201   202   203