Page 271 - Computer Science Class 11 With Functions
P. 271

06              print('digit')       #s2
                  07          if ch.isupper():
                  08              print('upper')       #s3
                  09          else:
                  10              print('Unknown')     #s4
                  11  countMessage('BijoyGhosh1@gmail.com')
             Ans.  (#s1, #s2, #s3, #s4:18, 1, 2, 19)
              17.  What will be the output produced on execution of the following code snippet?
                 for i in range(1,15,4):
                     print(i+i//2, end=', ')
             Ans.  1, 7, 13, 19,


                   Assertion and Reasoning Based Questions


                  The following questions are assertion(A) and reasoning(R) based. Mark the correct choice as
                  a.  Both A and R are true and R is the correct explanation of A
                  b.  Both A and R are true and R is not the correct explanation of A
                  c.  A is true but R is false
                  d.  A is false but R is true
               1.  Assertion (A):  An infinite loop never terminates.
                  Reasoning (R): A loop executes a set of statements repeatedly till the test condition is True.
               2.  Assertion(A):  Both for and while loops are iterative statements.
                  Reasoning(R):  The repeated execution of statements in a program is called iteration.
               3.  Assertion(A):  else clause is optional in for loop.
                  Reasoning(R):   The number of times a for loop with a range clause will execute will depend on the values returned by the
                              range().

             Ans.  1. a  2. b  3. b


                  Case Based Questions


               1.  Pushpreet has a deep interest in Mathematics and is also inclined towards computing skills. He wants to write a program in
                  Python that computes and displays the sum of the following series for an arbitrary n (he will provide the value of n when
                  the program is executed):
                  sum = 1 + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3 + 4) +  (1 + 2 + 3 + 4 + …+n)
                  Write a program for Pushpreet to complete the given task.
             Ans.  def sumSeries(num):
                      '''
                      Objective: To compute the sum of first n terms of the series
                      Input Parameters: num - numeric value
                      Return Value: total - numeric value
                      '''
                      total = 0
                      for i in range(2,  num+2):
                          term = 0
                          for j in range(1,   i):
                              term += j

                                                                                              Looping in Python  269
   266   267   268   269   270   271   272   273   274   275   276