Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

For Loop in Python

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the syntax of a for loop in Python?

a)

for item in iterable: # code to be executed

b)

for i in range(n): # code to be executed

c)

for element in list: # code to be executed

d)

for item in iterable: # code to be executed

2.

How do you define the range of a for loop in Python?

a)

By using the range() function with start, stop, and step parameters.

b)

By using the len() function with the iterable as the parameter.

c)

By using the start, stop, and step parameters directly in the for loop.

d)

By using the range() function with only the stop parameter.

3.

What is the purpose of the else statement in a for loop?

a)

To specify a block of code to be executed before the loop starts

b)

To specify a block of code to be executed if the loop completes normally

c)

To specify a block of code to be executed if the loop does not complete normally

d)

To specify a block of code to be executed after each iteration of the loop

4.

How many times does a for loop iterate if the range is (1, 5)?

a)

4

b)

2

c)

1

d)

3

5.

What is the output of the following code?

a)

0 1 2 Loop completed

b)

0 1 2

3

c)

0

1

2

d)

0 1 2

3

Loop completed

6.

What is the output of the following code? for i in range(1, 6, 2): print(i)

a)

1 2 3 4 5

b)

1 2 3 4

c)

1 3 5

d)

1 3 5 7

7.

What is the output of the following code? for i in range(5, 0, -1): print(i)

a)

1

2

3

4

5

b)

1

2

3

4

c)

5

4

3

2

1

d)

4

3

2

1

8.

What is the output of the following code?

a)

0 1

b)

0

1

Loop End

c)

0

1

2

d)

0

1

2

Loop End

9.

What is the output of the following code?

a)

0

3

b)

0

1

c)

1

2

d)

0

2

10.

What is the output of the following code?

a)

0 2 Loop completed

b)

0 1 Loop completed

c)

0 1 2 Loop completed

d)

0

2