Page 134 - Computer Genius Class 08
P. 134

Let's REFRESH


                     l  In Python, the body of the ‘if’ statement is indicated by the indentation. Body starts with an indentation
                       and the first unindented marks the end.
                     l  Python interprets non-zero values as True, while ‘None’ and 0 are interpreted as False.
                     l  The ‘if..else’  statement  evaluates  the test expression and will execute  the body only  if  the test
                       condition is True. If the condition is False, the body of ‘else’ is executed.
                     l  The ‘elif’ is short for ‘else if’. It allows us to check for multiple expressions.
                     l  The ‘For’ loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects.
                     l  The while loop in Python is used to iterate over a block of code as long as the test expression (condition)
                       is true.





                                                        Exercise




                  A. Tick ( ) the correct option.
                      1. Which of these is not a valid Python loop?

                          (i) For loop                                     (ii)  if loop

                         (iii) While loop                                  (iv)  None of these
                      2. What does an ‘if’ statement do?

                          (i) Closes the program                           (ii)  Makes a decision

                         (iii) Asks for input                              (iv)  Iterates an input
                      3. Which is the correct output for:
                         for i in range (1, 10):
                         print(i)

                          (i) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9                 (ii)  1, 2, 3, 4, 5, 6, 7, 8, 9, 10

                         (iii) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10            (iv)  1, 2, 3, 4, 5, 6, 7, 8, 9
                      4. This statement allows the user to check for multiple expression.

                          (i) For                                          (ii)  Else

                         (iii) Elif                                        (iv)  While
                  B. Fill in the blanks using the words given below.


                                                       rue   Looping    ne   Elif

                      1.  _____________ statement allows us to execute a set of code repeatedly.

                      2. In if-else statement in Python, there can have _____________ else block.





                      132    Computer Genius-VIII
   129   130   131   132   133   134   135   136   137   138   139