Page 230 - Computer Science Class 11 Without Functions
P. 230
C. Fill in the blanks.
1. The _______ block of the loop is executed when all the iterations of the loop have been executed.
2. In a for loop, the _______ variable keeps track of the number of times the body of the loop has been executed.
3. The _______ statement terminates the execution of the loop.
4. In the case of a nested loop, the _______ loop will iterate over the next element in the sequence only after all iterations of
the _______ loop have been executed.
5. If in a program, the test condition of a loop does not evaluate to False at all, then such a loop is called _______ loop.
6. The _______ statement is an empty statement in Python.
D. Answer the following questions:
1. Define iteration.
Ans: The repetition of statements is called iteration.
2. Identify the test expression from the following code:
num=2
while num<=10:
print(num)
num=num+1
Ans: num<=10
3. Name the essential components of any loop.
Ans: Sequence which may be a list, string, tuple or dictionary.
A control variable is a variable that takes the values in the sequence one by one.
Body of the loop.
4. Consider the following code snippet and determine the number of times print('In Loop')is executed:
counter = 10
while (counter < 20):
print('In Loop')
counter = counter - 10
else:
print(counter)
Ans: Infinite Loop. In Loop is printed infinite times.
5. What will be the output produced on execution of the following code snippet?
(i) sweet='ice cream'
for ch in sweet:
if ch in sweet:
print(ch, end='')
Ans: ice cream
(ii) sweet='ice cream'
for ch in sweet:
if ch in 'abcdefghijklmnopqrstuvwxyz':
print(ch, end='')
print()
Ans: icecream
(iii) sweet='ice cream'
for ch in sweet:
if ch not in 'abcdefghijklmnopqrstuvwxyz':
pass
print(ch, end='')
228 Touchpad Computer Science-XI

