Page 108 - TP_Play_V2.1_class7
P. 108

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

                      Output

                   Enter the marks: 60
                   Passed with C grade


                   Enter the marks: 87
                   Passed with A grade


                   Enter the marks: 30
                   Sorry!!!, You failed the exam.


                   Enter the marks: 79
                   Passed with B grade





                      Recap


                           The if statement is the simplest conditional statement.
                           In the  if…else statement,  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.
                           Python allows the nested if statement.

                           The if…elif…else ladder helps us to test multiple conditions and follows a top-down
                           approach.



                                                         Exercise



                  A.  Tick ( ) the correct option.

                      1. What will be the output of the following code:

                        x = 10
                        if x > 5:
                            print("x is greater than 5")

                        a.  x is greater than 5                           b.  10 is greater than 5

                        c.  Nothing will be printed                       d.  None of these

                      2. What will be the output of the following code if x = 3:

                       if (x % 2) == 0:

                           print("x is even")

                  106       Play (Ver. 2.1)-VII
   103   104   105   106   107   108   109   110   111   112   113