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

16.  Consider the code given below and determine the number of times each of the statements labelled #s1, #s2, #s3,
                  #s4 will be executed.
                  01 text = 'BijoyGhosh1@gmail.com'
                  02
                  03 for ch in text:
                  04     if ch.isalpha():
                  05         print('alphabet') #s1
                  06     elif ch.isdigit():
                  07         print('digit')    #s2
                  08     elif ch.isupper():
                  09         print('upper')    #s3
                  10     else:
                  11         print('Unknown')  #s4
             Ans:  (#s1, #s2, #s3, #s4:18, 1, 0, 2)
              17.  Consider the code given below and determine the number of  times each of the statements labelled #s1, #s2, #s3,
                  #s4 will be executed.
                  01 text = 'BijoyGhosh1@gmail.com'
                  02
                  03 for ch in text:
                  04     if ch.isalpha():
                  05         print('alphabet')    #s1
                  06     if ch.isdigit():
                  07         print('digit')       #s2
                  08     if ch.isupper():
                  09         print('upper')       #s3
                  10     else:
                  11         print('Unknown')     #s4
             Ans:  (#s1, #s2, #s3, #s4:18, 1, 2, 19)
              18.  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

               In the following question, a statement of Assertion (A) is followed by a statement of Reason (R).
               a.  Assertion (A) and reason (R) are true and reason (R) is the correct explanation of Assertion (A).
               b.  Assertion (A) and reason (R) are true and reason (R) is not the correct explanation of Assertion (A).
               c.  Assertion (A) is true but reason (R) is false.
               d.  Assertion(A) is false but reason (R) is true.

               1.  Assertion(A):  Both for and while loops are iterative statements.
                  Reasoning(R):  The repeated execution of statements in a program is called iteration.
               2.  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. b  2. b





                                                                                              Looping in Python  233
   230   231   232   233   234   235   236   237   238   239   240