Class Test: Looping in Python (20 Marks)
Grade 11 | Time: 30 minutes
Instructions: Answer all questions. Write proper indentation and syntax in code-
related answers.
A. Multiple Choice Questions (10 × 1 = 10 Marks)
1. What will be the output of the following code?
for i in range(3):
print('Hi')
a) Hi b) Hi Hi c) Hi Hi Hi d) Error
2. Correct syntax for a while loop:
a) while(x <= 5) b) while x <= 5:
c) while x <= 5 d) while(x <= 5):
3. What will range(2,10,2) produce?
a) [2,4,6,8,10] b) [2,4,6,8] c) [3,5,7,9] d) [2,3,4,5,6]
4. Keyword used to skip current iteration:
a) pass b) break c) stop d) continue
5. Output?
for i in range(5):
if i==3:
break
print(i)
a) 0 1 2 3 b) 0 1 2 c) 1 2 3 d) 0 1 2 3 4
6. Which creates an infinite loop? a) for i in range(5): b) while True: c) for i in [1,2,3]:
d) while False:
7. Loop inside another loop is called: a) Continuous loop b) Nested loop c) Infinite
loop d) Repeated loop
8. Identify error:
for i in range(5)
print(i)
a) Missing parenthesis b) Missing colon
c) Wrong variable d) No error
9. Output?
for i in range(1,6,2):
print(i, end=' ')
a) 1 2 3 4 5 b) 1 3 5 c) 2 4 6 d) 1 3 5 7
10. Truestatement:
a) break skips one iteration b) continue ends
loop
c) break ends loop completely d) continue ends
program
B. Very Short Answer (2 × 1 = 2 Marks)
1. Define an iterative statement in Python.
2. Write one difference between for loop and while loop.
C. Short Answer (4 × 2 = 8 Marks)
1. num =0
for i in range(1,6):
num += i
if num > 6:
break
print(num)
a) Write the output.
b) Explain what happens when num becomes greater than 6.
2. Find the Output:
for i in range(2):
for j in range(3,5):
print(i,j)
)a) Write the output.
b) How many times does the inner loop execute?
3. Find the Error and Correct it:
i=1
while i <= 5
print(i) i += 1
a) Identify syntax error. b) Write corrected code.
4. Predict the Output:
for i in 'HELLO':
if i == 'L':
continue
print(i)
a) What will be printed? b) Which statement skips letters?
5. Write the python code for the following:
a) 1
12
123
1234
b) # # # #
###
##
#
c) @
@@
@@@
@@@@
@@@@@
__________________________