Page 138 - TP_Plus_v4_Class7
P. 138

Timeline


                         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 which means nesting if statements within other if statements
                       to create more complex decision-making logic.
                         The if…elif…else ladder helps us to test multiple conditions and follows a top-down approach.






                     Choose the correct option.


                     1.  Which of the following conditional statements is used to test multiple conditions?

                              a.  if                                        b.  if…else

                              c.  if…elif…else                              d.  None of these
                     2.  What will be the output of the following code?

                          if(5>3):
                              print(“Hello”)
                          else:
                              print(“Hi”)

                              a.  Hello                                     b.  Hi

                              c.  Hello Hi                                  d.  Nothing will print
                     3.  Which of the following is not the conditional statement in Python?

                              a.  if Statement                              b.  if…else Statement

                              c.  if...elif...else Statement                d.  print
                     4.   In an if...elif...else statement, if none of the conditions evaluate to true, then which of the following
                        statements gets executed?

                              a.  Only else                                 b.  Only if

                              c.  Only if                                   d.  Nothing will be executed
                     5.  If a = 20 and b = 10, then find the output of the following code:

                        if (false):
                             print(a + b)

                        else:
                             print(a – b)

                              a.  30                                        b.  20
                              c.  10                                        d.  Error



                  136  Plus (Ver. 4.0)-VII
   133   134   135   136   137   138   139   140   141   142   143