Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 149 - CodePilot V5.0 C7
P. 149

    LEARNING LOGS

                     A.  Tick ( ) the correct option.

                        1.  Select the type of flow of control where statements are executed one after another.
                                   (i)  Iterative flow                       (ii)  Selective flow

                                  (iii)  Sequential flow                     (iv)  Nested flow

                        2.  Identify the function that is used to generate a sequence of numbers.

                                   (i)  sequence()                           (ii)  generate()

                                  (iii)  range()                             (iv)  list()

                        3.  Which of the following loops is used when the number of repetitions is not known in advance?
                                   (i)  for loop                             (ii)  while loop

                                  (iii)  break loop                          (iv)  continue loop

                        4.  Spot the output of the code:

                            for i in range(2, 7):
                                print(i + 3)

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

                                  (iii)  3, 4, 5, 6, 7                       (iv)  7, 8, 9, 10, 11

                        5.  Mark the correct syntax of the ternary operator in Python.
                                   (i)  if <condition> else <value_if_true> <value_if_false>

                                  (ii)  <value_if_true> if (condition) else <value_if_false>

                                  (iii)  if <value_if_true> else <condition> <value_if_false>

                                  (iv)  <condition> if <value_if_true> else <value_if_false>

                     B.  Fill in the blanks using the given hints:
                        1.  The             loop repeats a block of statements a fixed number of times.
                                                                                                                Hints
                        2.  The             statement lets your program choose between two options.            If…else…
                                                                                                                Infinite
                        3.   The            statement is used to exit a loop before it has completed all its     For
                                                                                                                Break
                            iterations.                                                                        Iteration

                        4.              means repeating a set of instructions again and again.

                        5.  An             loop never ends because its condition is always true and never becomes false.

                                                                                                                      147
                                                                                               Flow of Control in Python

| 144 145 146 147 148 149 150 151 152 153 154 |