Page 93 - TP-Play_V-2.0_Book-7
P. 93

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 of the following conditional statements is used to test multiple conditions?
                  a.  if                                            b.  if…else

                  c.  if…elif…else                                  d.  else

               2.  What will be the output of the following code?
                 if(True):
                     print(“Hello”)
                 else:
                     print(“Hi”)

                  a.  Hello                                         b.  Hi

                  c.  Nothing will print                            d.  Both a. and b.
               3.  Which of the following is not the conditional statement in Python?

                  a.  if Statement                                  b.  if…else Statement

                  c.  Nested if statement                           d.  None of these
               4.  What is the answer of the expression, 2**2**2?

                  a.  2                    b.  16                   c.  8                  d.  6

               5.  If a = 20 and b = 10, then what will be the output of the following code?
                 if (False):

                     print(a + b)

                 else:
                     print(a – b)
                  a.  30                   b.  20                   c.  10                 d.  25





                                                                      Conditional Statements in Python       93
   88   89   90   91   92   93   94   95   96   97   98