Page 117 - Touchpad_Plus_V3.2_Class 7
P. 117

On running the above program, we get the following output:

                                                                Output
                  Enter the name of the student: Amit
                  Enter the age of the student: 18
                  Enter the marks of the student: 57
                  Amit is too young for college


                  Enter the name of the student: Kanak
                  Enter the age of the student: 23
                  Enter the marks of the student: 87
                  Kanak is selected for college




                 Program 6: To check if the given number is lucky or not, if the given number is greater than zero
                 and is even, then print ‘Lucky number’ else print ‘Not a lucky number’.
                                                             Program6.py
                   File  Edit  Format  Run    Options   Window    Help


                  #Program to check lucky number
                  number = int(input('Enter a number: '))
                  if(number > 0):
                      if(number % 2 == 0):
                          print('Lucky number')
                      else:
                          print('Not a lucky number')
                  else:
                      print('Try again....')



                 On running the above program, we get the following output:

                                                                Output

                  Enter a number: 21
                  Not a lucky number


                  Enter a number: 12
                  Lucky number




                     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 true, the




                                                                              Conditional Statements in Python       115
   112   113   114   115   116   117   118   119   120   121   122