Page 332 - Computer Science V2.0 Class 11
P. 332

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
               318   Touchpad Computer Science (Ver. 2.0)-XI
   327   328   329   330   331   332   333   334   335   336   337