Page 94 - Dig_CodeAI_V2.1_Class_8
P. 94

REFRESH


                        The  statements  that  are  used  to  repeat  a  set  of  instructions  are  called  iterative  or  looping
                       statements.
                       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.
                       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.






                                                   TeCh Ready





                  A.  Tick ( ) the correct option.
                      1.  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).

                      2.  Which of the following is a looping statement in Python?
                          (i)  for statement                               (ii)  continue statement

                         (iii)  if statement                               (iv)  break statement

                      3.  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

                      4.  Which of the following statements terminates the execution of the loop?
                          (i)  if                                          (ii)  for

                         (iii)  break                                      (iv)  continue




                       92    DigiCode AI (Ver. 2.1)-VIII
   89   90   91   92   93   94   95   96   97   98   99