Page 156 - 2620_Birla Open Mind C-7
P. 156

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.






              A.     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



                  154  Premium Edition-VII
   151   152   153   154   155   156   157   158   159   160   161