Page 104 - modular4.0
P. 104

Chapter Profile
                  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.   Which approach is followed by the if…elif…else ladder?
                          a.   top-down approach                         b.   bottom-top approach

                          c.   top-left approach                         d.  bottom-right approach

                      2.  Which option best describes the if...else statement in Python?
                          a.  The if statement runs the code only if the condition is False.

                          b.  The else block runs if the if condition is True.
                          c.  If the condition is True, the code after the if runs; otherwise, the else block runs.

                          d.  The else block always runs.




                102  Modular (Ver. 4.0)-VII
   99   100   101   102   103   104   105   106   107   108   109