Page 125 - 2611_SmartGPT Pro V(5.0) C-7
P. 125

c.  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
                    d.  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

                    e.  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>
                 2.  Fill in the blanks using the words from the help box.


                                               If…else…, Infinite, For, Break, Iteration

                    a.  The ____________ loop repeats a block of statements a fixed number of times.

                    b.  The ____________ statement lets your program choose between two options.
                    c.  The ____________ statement is used to exit a loop before it has completed all its iterations.

                    d.  ____________ means repeating a set of instructions again and again.
                    e.  An ____________ loop never ends because its condition is always true and never becomes false.

                 3.  Write 'T' for true and 'F' for false.


                    a.  The elif statement allows you to check multiple conditions in an if-else construct.

                    b.  In an if statement, the condition is evaluated to either true or false.

                    c.  A while loop checks the condition after each repetition.


                    d.  Decisions are not made using the selection statement.

                    e.   The continue statement is used to skip the current iteration of the loop and move
                       to the next one.

                 4.  Think and answer.

                    a.  Write the syntax of the following:
                       (i)  if statement                              (ii)  if … else … statement
                           ________________________________                ________________________________

                           ________________________________                ________________________________
                           ________________________________                ________________________________



                                                                                           Flow of Control in Python  123
   120   121   122   123   124   125   126   127   128   129   130