wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Grade 7 – Python For Loops Questions

Total questions: 40

Worksheet time: 20mins

Name
Class
Date
1.

What does a for loop do in Python?

a)

Repeats a block of code

b)

Stops the program

c)

Defines a variable

d)

Creates a new function

2.

Which keyword is used to start a for loop?

a)

for

b)

loop

c)

repeat

d)

while

3.

What does range(5) generate?

a)

Numbers 0 to 4

b)

Numbers 1 to 5

c)

Numbers 0 to 5

d)

Only number 5

4.

How many times does this loop run? for i in range(3):

a)

3 times

b)

2 times

c)

4 times

d)

1 time

5.

What is i in for i in range(5)?

a)

Loop variable

b)

Function

c)

Condition

d)

String

6.

What will range(2, 6) produce?

a)

2,3,4,5

b)

2,3,4,5,6

c)

1,2,3,4,5

d)

3,4,5,6

7.

What type does range() return?

a)

A sequence

b)

A string

c)

A float

d)

A dictionary

8.

Which loop is best for repeating code a fixed number of times?

a)

for loop

b)

while loop

c)

if statement

d)

function

9.

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

a)

0 1 2

b)

1 2 3

c)

3 2 1

d)

Nothing

10.

Where should indentation be used?

a)

Inside loop body

b)

Before for

c)

After print

d)

No need

11.

What does range(1,10,2) generate?

a)

1 3 5 7 9

b)

1 2 3 4

c)

2 4 6 8

d)

1 5 9 13

12.

What does break do in a loop?

a)

Stops the loop

b)

Repeats the loop

c)

Skips iteration

d)

Restarts program

13.

What does continue do?

a)

Skips to next iteration

b)

Stops loop

c)

Repeats last step

d)

Exits program

14.

Can a for loop iterate over a list?

a)

Yes

b)

No

c)

Only numbers

d)

Only strings

15.

What will len([1,2,3]) return?

a)

3

b)

2

c)

1

d)

Error

16.

Which is correct?

a)

for x in [1,2,3]:

b)

loop x in list:

c)

repeat x:

d)

for each x:

17.

What will print? for c in 'abc': print(c)

a)

a b c

b)

abc

c)

a

d)

Nothing

18.

What does this loop do? for i in range(10): pass

a)

Does nothing

b)

Prints numbers

c)

Stops

d)

Repeats forever

19.

Which loop is this? for a in range(4):

a)

Counting loop

b)

While loop

c)

Conditional

d)

Function loop

20.

range(0) produces:

a)

An empty sequence

b)

0

c)

1

d)

Error

21.

A for loop can repeat code multiple times. (True / False)

a)

True

b)

False

22.

range(5) gives numbers 1 to 5. (True / False)

a)

True

b)

False

23.

Indentation is required inside a for loop. (True / False)

a)

True

b)

False

24.

A for loop can iterate through a string. (True / False)

a)

True

b)

False

25.

range(3) produces 0,1,2. (True / False)

a)

True

b)

False

26.

break stops the entire loop. (True / False)

a)

True

b)

False

27.

continue skips the current iteration. (True / False)

a)

True

b)

False

28.

You must use range() in every for loop. (True / False)

a)

True

b)

False

29.

A for loop can iterate over a list. (True / False)

a)

True

b)

False

30.

Python is case-sensitive. (True / False)

a)

True

b)

False

31.

range(2,8) includes number 8. (True / False)

a)

True

b)

False

32.

for i in range(1) runs once. (True / False)

a)

True

b)

False

33.

A loop variable changes every iteration. (True / False)

a)

True

b)

False

34.

You can nest one loop inside another. (True / False)

a)

True

b)

False

35.

Strings are sequences in Python. (True / False)

a)

True

b)

False

36.

range(10,0,-1) counts down. (True / False)

a)

True

b)

False

37.

A loop cannot run zero times. (True / False)

a)

True

b)

False

38.

for loops always need a list. (True / False)

a)

True

b)

False

39.

Loops help reduce repeated code. (True / False)

a)

True

b)

False

40.

pass means 'do nothing'. (True / False)

a)

True

b)

False