Page 79 - Touhpad Ai
P. 79

Program 20: To demonstrate the use of a range () with only stop value

                   for i in range(5):
                       print(i)
                   Output:

                   0
                   1
                   2
                   3
                   4
                 2.   range(start, stop): This generates a sequence of number beginning with start and going up to stop, but not including
                   the specified stop value. It increments by 1 step.

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

                   for i in range(20, 25):
                       print(i)
                   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
                     AI 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



                                                                                 Basic Concepts of Artificial Intelligence  77
   74   75   76   77   78   79   80   81   82   83   84