Page 134 - Trackpad_V4.0_c7_Flpbook
P. 134

2.  What will be the output of the following code if x = 3:

                         if (x % 2) == 0:

                             print("x is even")
                         else:
                             print("x is odd")
                               a. x is even                                   b. x is odd


                               c. Both a. and b.                              d. None of these

                     3.  Which of the following is the result of a conditional expression?

                               a. Always True                                 b. Always False

                               c. Both a. and b.                              d. Either True or False

                     4.  Which of the following statement is true about nested if statement?

                               a.  The second nested if indented block will run only when the first if condition evaluates to be
                                 True.

                               b.  The second nested if indented block will run only when the first if condition evaluates to be
                                 False.
                               c.  The if statement inside other if statement is called nested if.


                               d. Both a. and c.

                     5.   Ravi wants to create a program in Python that assigns grades (A, B, C, and D) to the students according
                        to their percentage of marks. Which of the following is the best suitable option to achieve this?

                               a. Simple if statement                         b. The if…else statement

                               c. The if…elif…else statement                  d. None of these


                     Fill in the blanks with the correct words.


                                                    Hints  True, top-down, elif, False


                     1.  If a conditional expression return              , statements inside the if block are executed.

                     2.  The else part is executed only when the condition specified with if returns            .
                     3.  The if…elif…else ladder follows a               approach.

                     4.  There can be multiple                 blocks with the if block.


                Q    Answer the following questions:
                  A
                     1.  What will be the output of the following code, if x = -10:

                        if (x > 10):




                        Premium Edition-VII
                132
   129   130   131   132   133   134   135   136   137   138   139