Page 129 - TechPluse_C8_Flipbook
P. 129

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



























                 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.
                 The syntax of the if…else statement is given below:                  Test
                                                                                   Expression
                 Syntax:
                                                                                                               False
                 if (Test Expression):                                                   True
                     Indented block
                                                                                    Body of if          Body of else
                 else:
                     Indented block


                                                                              Statement just below
                                                                                     if...else





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























                                                                Conditional and Looping Statements in Python         127
   124   125   126   127   128   129   130   131   132   133   134