Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 87 - 2612_Digimind
P. 87

    REVISIT

                           Iterative statements refer to the statements that are used to repeat a task based on a given condition.
                           The for loop is a type of iterative statement that allows the user to repeat a set of statements multiple times
                         until a given condition is falsified.
                           The range() function is an in-built function in Python. This function generates a sequence of numbers.
                           The while loop repeats a block of statements while a given condition is true.
                           Jump statements are used to jump out of the loop iterations even if the condition has not become False.
                           The break statement is used for exiting the program control out of the loop.
                           The continue statement causes the program to skip the rest of the statement of the current block and move
                         to the next iteration of the loop.

                     1.  Tick ( ) the correct option.
                        a.   Vedika wants to print numbers from 1 to 10 where the number of repetitions is already known.
                            Which loop should she use?

                             (i)   while loop                                 (ii)  infinite loop
                            (iii)   for loop                                 (iv)  conditional loop
                        b.  Yash wants to print only odd numbers till 10 Which range() call is correct?

                             (i)   range(1,10)                                (ii)  range(0,10,2)
                            (iii)   range(1,10,2)                            (iv)  range(10)

                        c.  A loop checks the condition first and then executes statements. Which loop is this?
                             (i)  for loop                                    (ii)  while loop
                            (iii)   nested loop                              (iv)  jump loop

                        d.   Sameer wants to skip the current iteration and move to the next in his loop. Which statement
                            should he use?

                             (i)  continue                                    (ii)  break
                            (iii)  pass                                      (iv)  return

                        e.  A teacher wants students to print numbers from 0 to 4. Which statement is correct?
                             (i)  range(0,4)                                  (ii)  range(1,5)
                            (iii)  range(5)                                  (iv)  range(4)

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

                                                    Break, for, repeat, one, continue

                        a.  Iterative statements are used to _______________ a task.
                        b.  By default, the step_size of range() is _______________.

                                                                                                    Iteration in Python  85

| 82 83 84 85 86 87 88 89 90 91 92 |