Worksheetsgrade 9 week 12
Total questions: 50
Worksheet time: 50mins
Which keyword is used to create a loop in Python?
loop
repeat
for
iterate
What will this code print? for i in range(3): print(i)
a) 1 2 3
b) 0 1 2
c) 0 1 2 3
d) 1 2
What does the range(5) function generate?
[1, 2, 3, 4, 5]
[0, 1, 2, 3, 4]
[0, 5]
[5, 4, 3, 2, 1]
Which loop is used when the number of iterations is unknown?
for
while
repeat
iterate
What is the output of: count = 0 while count < 3: print("Hi") count += 1
1 Hi
2 Hi
3 Hi
Infinite Hi
Which of these loops will never stop?
Infinite loop
Finite loop
Nested loop
What is required to avoid an infinite while loop?
break statement
condition update inside loop
range()
print()
What does break do inside a loop?
Skips one iteration
Stops the loop completely
Restarts the loop
Jumps to the next loop
What does continue do inside a loop?
Ends the loop
Skips the rest of the code in the current iteration
Restarts the program
Repeats the same line
How many times will this loop run?
8 times
4 times
5 times
3 times
Which of the following is a valid syntax?
for i = range(5):
for i in range(5)
for i in range(5):
loop i range(5)
What keyword is used to skip one loop iteration?
skip
next
continue
pass
What is printed by this code? i = 0 while i < 3: print(i) i += 2
0 2
0 1 2
0 1
0 2 4
Which loop is guaranteed to run at least once?
for loop
while loop
do-while loop
None in Python
What happens if you forget to increase a counter in while loop?
Syntax error
Loop stops automatically
Infinite loop
No output
Which loop is best for reading user input until “exit” is entered?
for loop
while loop
range loop
counter loop
x = 0 while x < 5: x += 1 print(x)
0
4
5
Error
Which statement does nothing when executed?
skip
none
pass
continue
Which loop will never execute?
Executes once
Executes twice
Never executes
Infinite loop
What will this print? for x in [1, 2, 3]: print(x)
a) 1 2 3
b) [1, 2, 3]
c) 0 1 2
d) Error
What does this code print? for letter in "Hi": print(letter)
H
i
What will happen? for i in []: print(i)
Nothing printed
Error
Infinite loop
Prints “None”
What does range(1, 6) generate?
1 2 3 4 5
0 1 2 3 4 5
1 2 3 4 5 6
2 3 4 5 6
Which loop will print even numbers only?
0 1 2 3 4
0 2 4 6 8
2 4 6 8 10
1 3 5 7 9
What will be printed? for i in range(1, 10, 3): print(i)
a) 1 4 7
b) 1 3 6 9
c) 1 4 7 10
d) 3 6 9
Which loop will print numbers backwards?
Hi
H i
"Hi"
Error
for i in range(5, 0, -1): print(i)
1 2 3 4 5
5 4 3 2 1
0 1 2 3 4 5
4 3 2 1
How many times will this print?
3
6
2
9
What will be printed last?
Inner: 1
Outer: 2
Inner: 2
Outer: 3
What is the purpose of nested loops?
To repeat inside a repeat
To create functions
To end a loop early
To skip iterations
What keyword ends both for and while loops early?
continue
stop
What will this print? for i in range(5): if i == 2: break print(i)
0 1 2 3 4
0 1
2 3 4
0
What will this print? for i in range(4): if i == 2: continue print(i)
a) 0 1 2 3
b) 0 1 3
c) 1 2 3
d) 2 3
What does the else in a loop do?
Runs when loop breaks
Runs after loop finishes normally
Runs before loop starts
Runs if loop is infinite
for i in range(3): print(i) else: print("Done") Output:
a) 0 1 2 Done
b) Done 0 1 2
c) Done only
d) Error
When does the else part of a loop not run?
When loop finishes
When loop has break
When loop starts
Always runs
Which loop type can use else?
for loop only
while loop only
both for and while
neither
What is printed? for i in range(3): pass print("End")
0 1 2 End
End
None
Error
What is the output? for i in range(2): for j in range(2): print(i + j)
0 1 2 3
0 1 1 2
1 2 3 4
0 1 1 2 2 3
What will happen if we use break in an inner loop?
Stops both loops
Stops only the inner loop
Restarts outer loop
Skips iteration
How to loop over a list named colors?
for i in colors:
for colors in i:
for list in colors:
colors for i in:
What will this output? for i in range(1, 10): if i % 2 == 0: print(i)
Even numbers from 1–10
Odd numbers from 1–10
1 to 10
Error
What is printed? x = 0 while x < 3: print(x) x += 1 else: print("done")
0 1 2
0 1 2 Done
Done
0 Done
Which is not a loop control statement?
break
continue
stop
pass
What will happen if range(0) is used?
Runs once
Runs infinitely
No loop runs
Error
For i in range(3): print("A") print("B")
A B A B A B
A A A B
A B
B A
What is printed by this code? for i in range(1, 4): print(i * "*")
1 2 3
* ** ***
1* 2* 3*
Error
Which loop would you use to print "Hello" 5 times?
for i in range(5): print("Hello")
while 5: print("Hello")
repeat 5 print("Hello")
print("Hello") * 5
What happens if break is inside while True?
Loop never ends
Loop stops when break runs
Error
Program restarts
Which of the following best describes a loop?
Repeating code until a condition is met
Running a single command once
Stopping execution
Copying data
