Page 118 - Touchpad_Plus_V3.2_Class 7
P. 118

indented block associated with that  ‘if’
                  is executed, and the rest of the ladder is
                                                                             Start
                  avoided.
                  If none  of  the  conditions evaluates  to
                  true,  then  the  final else statement  gets                           True
                                                                         if condition 1           block 1
                  executed.
                  The syntax of if...elif...else ladder is shown                False
                  below:
                                                                                         True
                  Syntax:                                                if condition 2            block 2
                  if (Test Expressions_1):
                                                                                False
                      Indented block 1
                                                                                         True
                  elif (Test Expression_2):
                                                                         if condition 3            block 3
                      Indented block 2
                                                                                False               block
                  elif (Test Expression_3):

                      Indented block 3
                                                                                                               Stop
                  else:

                      Indented block


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

                    File  Edit  Format   Run   Options   Window    Help
                                                                                     Enter a number: 23
                    num = int(input('Enter a number: '))                             Two digit number
                    if(9 < num <= 99):
                        print('Two digit number')                                    Enter a number: 345
                    elif(99 < num <= 999):                                           Three digit number
                        print('Three digit number')
                    elif(999 < num <= 9999):                                         Enter a number: 4564
                        print('Four digit number')                                   Four digit number




                  Program 8:  To print the message based on the marks entered, the messages displayed are:
                  1.  ‘Sorry!!!, You failed the exam.’, if the marks are less than 35.










               116      Plus (Ver. 3.2)-VII
   113   114   115   116   117   118   119   120   121   122   123