Page 98 - modular4.0
P. 98

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

                      Output

                   How many days are there in a leap year? 366

                   Your answer is correct, Good Job



                   How many days are there in a leap year? 365






                         THE IF…ELSE STATEMENT


                  The if…else statement checks for a condition. If the condition evaluates to True, the indented block
                  following the if statement is executed, otherwise the indented block after the else statement is
                  executed.
                  Syntax:                                                            Start

                  if (Test Expression):
                      Indented block

                  else:                                                           if condition
                                                                                                              False
                      Indented block
                                                                                        True
                                                                                                     Statements in else
                                                                                Statements in if
                                                                                                       block execute
                                                                                 block execute


                                                                                     Stop




                  Program 3: To compare two numbers and print the result.


                      Program3.py
                   File  Edit  Format   Run   Options  Window    Help

                   #Program to compare two numbers using if else statement
                   a = int(input('Enter the first number: '))
                   b = int(input('Enter the second number: '))
                   if(a > b):
                       print('First number is greater than second number')
                   else:
                       print('Second number is greater than first number')











                96   Modular (Ver. 4.0)-VII
   93   94   95   96   97   98   99   100   101   102   103