Page 102 - modular4.0
P. 102

Chapter Profile
                         THE IF…ELIF…ELSE LADDER


                  The if…elif…else ladder is another type of if statement. It helps us to test multiple conditions and

                  follows a top-down approach. In this, as soon as the condition of the if evaluates to be true, the

                  indented block associated with that if is executed, and the rest of the ladder is avoided. If none of
                  the conditions evaluates to true, then the final else statement gets executed.

                  Syntax:
                  if (Test Expressions_1):                               Start

                      Indented block 1
                  elif (Test Expression_2):                                           True
                                                                     if condition 1            block 1
                      Indented block 2
                  elif (Test Expression_3):                                 False
                      Indented block 3
                                                                                      True
                  else:                                               if condition 2           block 2
                      Indented block 4
                                                                            False

                                                                                      True
                                                                      if condition 3           block 3



                                                                            False
                                                                                                block


                                                                                                          Stop

                  Program 7: To check whether a given number is two-digit number, three-digit number or
                  four-digit number


                      Program7.py
                   File  Edit  Format   Run   Options  Window    Help

                   num = int(input('Enter a number: '))
                   if(9 < num <= 99):
                       print('Two digit number')
                   elif(99 < num <= 999):
                       print('Three digit number')
                   elif(999 < num <= 9999):
                       print('Four digit number')















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