Page 99 - TP_Modular_V2.1_Class7
P. 99

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")

                                                                           Conditional Statements in Python       97
   94   95   96   97   98   99   100   101   102   103   104