Page 171 - Information_Practice_Fliipbook_Class11
P. 171

counter: 8
                  counter: 12
                  s3 and s5 will not get executed

              16.  Consider the code given below and determine the number of times each of the statements labelled #s1, #s2, #s3,
                  #s4 will be executed.

                  text = 'BijoyGhosh1@gmail.com'

                  for ch in text:
                      if ch.isalpha():
                          print('alphabet') #s1
                      elif ch.isdigit():
                          print('digit')    #s2
                      elif ch.isupper():
                          print('upper')    #s3
                      else:
                          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.
                  text = 'BijoyGhosh1@gmail.com'


                  for ch in text:
                      if ch.isalpha():
                          print('alphabet')    #s1
                      if ch.isdigit():
                          print('digit')       #s2
                      if ch.isupper():
                          print('upper')       #s3
                      else:
                          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


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



                                                                                              Looping in Python  157
   166   167   168   169   170   171   172   173   174   175   176