Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 122 - 2620_Birla Open Mind C-8
P. 122

    Timeline

                             Looping statements are very useful and necessary for developing applications.

                             Python provides two types of looping statements—for and while.
                             The for statement executes a simple or compound statement for a fixed number of times.
                            The range() function is an in-built function of Python.
                             A sequence is a succession of values bound together by a single name.

                             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.

                  A.     Choose the correct option.

                          1.  What does while loop do?
                                   a.  Repeats a chunk of code a given number of times

                                   b.  Repeats a chunk of code until a condition is true

                                   c.  Repeats a chunk of code until a condition is false

                                   d.  Repeats a chunk of code indefinitely

                          2.  Which of the following is/are a looping statement/statements in Python?

                                   a.  for statement                            b.  while statement

                                   c.  break statement                          d.  Both a. and b.

                          3.  Which of the following statements allow/allows to repeat a task for a fixed number of times?
                                   a.  for statement                             b.  if statement

                                   c.  continue statement                       d.  Both a. and b.

                          4.  Which of the following statements terminates the execution of the loop?
                                   a.  if                                       b.  for

                                   c.  break                                    d.  continue

                  B.     Fill in the blanks with the correct words.

                                              Hints  infinite, break, while, continue, non-zero, false

                          1.   The                  statement executes a set of statements repeatedly, until the logical
                             expression remains true.

                      120  Premium Edition-VIII

| 117 118 119 120 121 122 123 124 125 126 127 |