Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 129 - 2609_Logicode
P. 129

    ▶   The while statement executes a set of statements repeatedly, until the logical expression evaluates to true.

                       ▶   To come out of the infinite loop, we can either close the program window or press Ctrl + C.
                       ▶  The else block is executed when the condition given in the while statement becomes false.
                       ▶   The break is a keyword in Python which is used for bringing the program control out of the loop.

                       ▶  When a continue statement is encountered inside a loop, control of the program jumps to the beginning of
                         the loop for next iteration, skipping the execution of rest of the statements of the loop.

                     1.  Tick ( ) the correct option.

                        a.  What is the use of range(n) function?
                             (i)  Generates a set of whole numbers starting from 0 to (n+1).
                            (ii)  Generates a set of whole numbers starting from 1 to (n+1).

                            (iii)  Generates a set of whole numbers starting from 0 to (n-1).
                           (iv)  Generates a set of whole numbers starting from 1 to (n-1).

                        b.  Which of the following is a looping statement in Python?
                             (i)  for statement                               (ii)  continue statement
                            (iii)  if statement                              (iv)  break statement

                        c.  Which of the following statements allow to repeat a task for a fixed number of times?
                             (i)  for statement                               (ii)  while statement

                            (iii)  if…else statement                         (iv)  continue statement
                        d.  Which of the following statements terminates the execution of the loop?
                             (i)  if                                          (ii)  for

                            (iii)  break                                     (iv)  continue

                     2.  Fill in the blanks using the words from the help box.

                                                 infinite, break, iterative, continue, two

                        a.   Looping statements are also knowns as                   statements.

                        b.   Python provides                   types of looping statements.
                        c.  The                    loop never ends.

                        d.  The                    and                    are the jump statements in Python.

                                                                                           Looping Statements in Python  127

| 124 125 126 127 128 129 130 131 132 133 134 |