Page 28 - PlusGPT_V2.1_C8_Flipbook
P. 28

Program 2: To demonstrate the if statement.














                  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    Test Expression
                  statement is executed, otherwise the indented block after
                  the  else  statement  is  executed.  The  syntax  of  the  if…else      True                  False
                  statement is given below:
                  Syntax:                                                           Body of if           Body of else

                  if (Test Expression):

                      Indented block
                                                                               Statement just below if...else
                  else:
                      Indented block


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


















                  26    Premium Edition-VIII
   23   24   25   26   27   28   29   30   31   32   33