Page 201 - Ai Book - 10
P. 201

Example:








        If-elif-else Statement

        Sometimes, just a single test condition is not sufficient to take a decision but, it may be several other conditions
        which needs to be tested in cascading order. In such situations, if…elif…else statement is used.
              if<condition>:
                  Set of Statements
              elif<condition>:
                  Set of statements
              elif<condition>:
                  Set of statements
              else:
                  Set of statements
        Let us make a program using if….elif….else conditional statement in which user enters a choice.





















        Iterative Statement

        Iterative statement or looping statement refers to those statements which are used to repeat a set of statements
        for the specified number of times until a certain condition is fulfilled. As soon as the condition becomes false, the
        loop terminates. These statements consist of three values:
         u   A starting value(i.e. initializing the starting value of a variable)

         u   A test expression
         u   A step value(Using increment or decrement operator)
        In Python, the two basic type of iterative statement are as follows:

         u   for loop
         u   while loop
        For Loop

        The For loop statement is used to repeat itself over a range of values or sequences when the number of iterations
        are known.


                                                                                                              75
                                                                                                              75
   196   197   198   199   200   201   202   203   204   205   206