Page 238 - Computer Science Class 11 Without Functions
P. 238

7.  What will be the value of num after the following code is executed?

              for num in range(10,   5,   -2):
                  break
              a.  -2                   b. 5                   c. 6                   d. 10
           8.  Which of the following  is not a valid construct?
              a.  while-else           b. if-else             c. def-else            d. for-else
           9.  What will be the output produced on the execution of the following code?
              value = 1
              while value<=4:
                  value = 1
              print(value)
              a.  4                    b. 5                   c. 6                   d. No output

        B.  State whether the following statements are True or False:
           1.  The body of a loop should consist of more than one statement.                           __________
           2.  Statements in the body of the loop are indented at the level of indentation  next to the level at which
              the header is indented.                                                                  __________
           3.  Statements in else block are executed when the loop terminates due to break statement.    __________
           4.  The continue statement skips the body of the loop and the control moves out of the loop.    __________
           5.  The statements in a while block will be executed as long as the condition specified in the header
              clause of the while statement is True.                                                   __________
           6.  While specifying a range, it is optional to specify the start value.                    __________
        C.  Fill in the blanks.
           1.  Repeated execution of a sequence of statements is called ____________.
           2.  The ____________ block of a for loop will be executed on successful execution (not on an abrupt exit) of a for loop.
           3.  The ____________ statement terminates the loop unconditionally.
           4.  In a nested loop,   the break statement appearing in an inner loop terminates only the ____________ loop.
           5.  An execution of the loop’s body is called an ____________ of the loop.
        D.  Answer the following questions:
           1.  Differentiate between:
              a.  for loop and while loop
              b.  break and continue statements
           2.  How is the else clause in an if statement different from the else clause in a for loop?
           3.  What is an infinite loop? Explain with an example.
           4.   What is the error in the following code:
              n =int(input("Enter a number"))
              while n!=0:
                 count = count + 2
              else:
                 print("Total Count"+count)
           5.  Rewrite the following code using for loop.
              moon = 50
              while(moon>0):
                  print(moon//5)
                  moon = moon - 5
                Now, when you have two codes that achieve the same functionality (one using the for  statement and the while
              statement), which one will you prefer and why?




         236   Touchpad Computer Science-XI
   233   234   235   236   237   238   239   240   241   242   243