Page 331 - Computer Science V2.0 Class 11
P. 331
Ans. counter: 1
counter: 5
counter: 9
counter: 13
Exit from loop
Statements s2 and s3 will not get executed
14. When the following code is executed, what output will be produced. Also, indicate which of the statements labelled s1,
s2, s3, s4, and s5 will not get executed?
01 counter = 0
02 while counter <= 16:
03 if counter < 16:
04 print('counter: ', counter) #s1
05 else:
06 break #s2
07 print('Stop') #s3
08 counter += 4 #s4
09 else:
10 print('Exit from loop') #s5
Ans. counter: 0
counter: 4
counter: 8
counter: 12
Statements s3 and s5 will not get executed
15. Consider the code given below and determine the number of times each of the statements labelled #s1, #s2, #s3,
#s4 will be executed.
01 def countMessage(text):
02 for ch in text:
03 if ch.isalpha():
04 print('alphabet') #s1
05 elif ch.isdigit():
06 print('digit') #s2
07 elif ch.isupper():
08 print('upper') #s3
09 else:
10 print('Unknown') #s4
11 countMessage('BijoyGhosh1@gmail.com')
Ans. (#s1, #s2, #s3, #s4:18, 1, 0, 2)
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 def countMessage(text):
02 for ch in text:
03 if ch.isalpha():
04 print('alphabet') #s1
05 if ch.isdigit():
Looping in Python 317

