wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

grade 9 week 12

Total questions: 50

Worksheet time: 50mins

Name
Class
Date
1.

Which keyword is used to create a loop in Python?

a)

loop

b)

repeat

c)

for

d)

iterate

2.

What will this code print? for i in range(3): print(i)

a)

a) 1 2 3

b)

b) 0 1 2

c)

c) 0 1 2 3

d)

d) 1 2

3.

What does the range(5) function generate?

a)

[1, 2, 3, 4, 5]

b)

[0, 1, 2, 3, 4]

c)

[0, 5]

d)

[5, 4, 3, 2, 1]

4.

Which loop is used when the number of iterations is unknown?

a)

for

b)

while

c)

repeat

d)

iterate

5.

What is the output of: count = 0 while count < 3: print("Hi") count += 1

a)

1 Hi

b)

2 Hi

c)

3 Hi

d)

Infinite Hi

6.

Which of these loops will never stop?

a)

Infinite loop

b)

Finite loop

c)

Nested loop

7.

What is required to avoid an infinite while loop?

a)

break statement

b)

condition update inside loop

c)

range()

d)

print()

8.

What does break do inside a loop?

a)

Skips one iteration

b)

Stops the loop completely

c)

Restarts the loop

d)

Jumps to the next loop

9.

What does continue do inside a loop?

a)

Ends the loop

b)

Skips the rest of the code in the current iteration

c)

Restarts the program

d)

Repeats the same line

10.

How many times will this loop run?

a)

8 times

b)

4 times

c)

5 times

d)

3 times

11.

Which of the following is a valid syntax?

a)

for i = range(5):

b)

for i in range(5)

c)

for i in range(5):

d)

loop i range(5)

12.

What keyword is used to skip one loop iteration?

a)

skip

b)

next

c)

continue

d)

pass

13.

What is printed by this code? i = 0 while i < 3: print(i) i += 2

a)

0 2

b)

0 1 2

c)

0 1

d)

0 2 4

14.

Which loop is guaranteed to run at least once?

a)

for loop

b)

while loop

c)

do-while loop

d)

None in Python

15.

What happens if you forget to increase a counter in while loop?

a)

Syntax error

b)

Loop stops automatically

c)

Infinite loop

d)

No output

16.

Which loop is best for reading user input until “exit” is entered?

a)

for loop

b)

while loop

c)

range loop

d)

counter loop

17.

x = 0 while x < 5: x += 1 print(x)

a)

0

b)

4

c)

5

d)

Error

18.

Which statement does nothing when executed?

a)

skip

b)

none

c)

pass

d)

continue

19.

Which loop will never execute?

a)

Executes once

b)

Executes twice

c)

Never executes

d)

Infinite loop

20.

What will this print? for x in [1, 2, 3]: print(x)

a)

a) 1 2 3

b)

b) [1, 2, 3]

c)

c) 0 1 2

d)

d) Error

21.

What does this code print? for letter in "Hi": print(letter)

a)

H

b)

i

22.

What will happen? for i in []: print(i)

a)

Nothing printed

b)

Error

c)

Infinite loop

d)

Prints “None”

23.

What does range(1, 6) generate?

a)

1 2 3 4 5

b)

0 1 2 3 4 5

c)

1 2 3 4 5 6

d)

2 3 4 5 6

24.

Which loop will print even numbers only?

a)

0 1 2 3 4

b)

0 2 4 6 8

c)

2 4 6 8 10

d)

1 3 5 7 9

25.

What will be printed? for i in range(1, 10, 3): print(i)

a)

a) 1 4 7

b)

b) 1 3 6 9

c)

c) 1 4 7 10

d)

d) 3 6 9

26.

Which loop will print numbers backwards?

a)

Hi

b)

H i

c)

"Hi"

d)

Error

27.

for i in range(5, 0, -1): print(i)

a)

1 2 3 4 5

b)

5 4 3 2 1

c)

0 1 2 3 4 5

d)

4 3 2 1

28.

How many times will this print?

a)

3

b)

6

c)

2

d)

9

29.

What will be printed last?

a)

Inner: 1

b)

Outer: 2

c)

Inner: 2

d)

Outer: 3

30.

What is the purpose of nested loops?

a)

To repeat inside a repeat

b)

To create functions

c)

To end a loop early

d)

To skip iterations

31.

What keyword ends both for and while loops early?

a)

continue

b)

stop

32.

What will this print? for i in range(5): if i == 2: break print(i)

a)

0 1 2 3 4

b)

0 1

c)

2 3 4

d)

0

33.

What will this print? for i in range(4): if i == 2: continue print(i)

a)

a) 0 1 2 3

b)

b) 0 1 3

c)

c) 1 2 3

d)

d) 2 3

34.

What does the else in a loop do?

a)

Runs when loop breaks

b)

Runs after loop finishes normally

c)

Runs before loop starts

d)

Runs if loop is infinite

35.

for i in range(3): print(i) else: print("Done") Output:

a)

a) 0 1 2 Done

b)

b) Done 0 1 2

c)

c) Done only

d)

d) Error

36.

When does the else part of a loop not run?

a)

When loop finishes

b)

When loop has break

c)

When loop starts

d)

Always runs

37.

Which loop type can use else?

a)

for loop only

b)

while loop only

c)

both for and while

d)

neither

38.

What is printed? for i in range(3): pass print("End")

a)

0 1 2 End

b)

End

c)

None

d)

Error

39.

What is the output? for i in range(2): for j in range(2): print(i + j)

a)

0 1 2 3

b)

0 1 1 2

c)

1 2 3 4

d)

0 1 1 2 2 3

40.

What will happen if we use break in an inner loop?

a)

Stops both loops

b)

Stops only the inner loop

c)

Restarts outer loop

d)

Skips iteration

41.

How to loop over a list named colors?

a)

for i in colors:

b)

for colors in i:

c)

for list in colors:

d)

colors for i in:

42.

What will this output? for i in range(1, 10): if i % 2 == 0: print(i)

a)

Even numbers from 1–10

b)

Odd numbers from 1–10

c)

1 to 10

d)

Error

43.

What is printed? x = 0 while x < 3: print(x) x += 1 else: print("done")

a)

0 1 2

b)

0 1 2 Done

c)

Done

d)

0 Done

44.

Which is not a loop control statement?

a)

break

b)

continue

c)

stop

d)

pass

45.

What will happen if range(0) is used?

a)

Runs once

b)

Runs infinitely

c)

No loop runs

d)

Error

46.

For i in range(3): print("A") print("B")

a)

A B A B A B

b)

A A A B

c)

A B

d)

B A

47.

What is printed by this code? for i in range(1, 4): print(i * "*")

a)

1 2 3

b)

* ** ***

c)

1* 2* 3*

d)

Error

48.

Which loop would you use to print "Hello" 5 times?

a)

for i in range(5): print("Hello")

b)

while 5: print("Hello")

c)

repeat 5 print("Hello")

d)

print("Hello") * 5

49.

What happens if break is inside while True?

a)

Loop never ends

b)

Loop stops when break runs

c)

Error

d)

Program restarts

50.

Which of the following best describes a loop?

a)

Repeating code until a condition is met

b)

Running a single command once

c)

Stopping execution

d)

Copying data