wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

For Loop python

Total questions: 19

Worksheet time: 11mins

Name
Class
Date
1.

Look at the following code, what will it generate

a)

1,2,3,4,5,6,7,8,9,10,11,12

b)

0,1,2,3,4,5,6,7,8,9,10,11,12

c)

1,2,3,4,5,6,7,8,9,10,11,12,13

d)

0,1,2,3,4,5,6,7,8,9,10,11,12,13

2.

What does the following program display?

a)

1,2,3,4

b)

1,2,3,4,5

c)

counter,counter,counter,counter,counter

d)

0,1,2,3,4,5

3.
a)
b)
c)
d)

1,2,3,4

4.
What button do you press to compile (run) your program so that it runs in the shell?
a)
F3
b)
F5
c)
F7
d)
F9
5.

#What is the output?

a)

1,2,3,4,5

b)

0,1,2,3,4

c)

1,2,3,4

d)

5,4,3,2,1

6.

#How many hallos will be printed?

a)

5

b)

None

c)

4

d)

6

7.

#What is the output?

a)

a, b, c, d, e

b)

a, a, a, a, a

c)

0,1,2,3,4

d)

e, d, c, b, a

8.
How many times does the following program print the word ‘computer’:

word= "computer"  
for num in range(1,6):
 
    print(word)
a)
5
b)
6
c)
1
d)
0
9.
What is iteration known as?
a)
Looping
b)
Crashing
c)
Repeating
10.
What will be printed after running this FOR loop:

for number in range(6):
 
    print(number)
a)
The number 6 
b)
The numbers 0 - 5
c)
The number 5
d)
The numbers 1 - 6
11.
How many times does the following program print the word ‘computer’:

word= "computer"  
for num in range(1,6):
 
    print(word)
a)
5
b)
6
c)
1
d)
0
12.

Which of the following programs prints ten lines?

a)

for i in range(10):

print("hi")

b)

for i = 1 to 10:

print("hi")

c)

for i in 1 - 10:

print("hi")

d)

for i from 0 to 9:

print("hi")

13.

Which of the following for loops would print the following numbers?

3

5

7

9

a)

for i in range(3, 10, 2):

print(i)

b)

for i in range(3, 9, 2):

print(i)

c)

for i in range(9):

print(i)

d)

for i in range(3,9):

print(i)

14.

What would be the output of the following code:

for i in range(3):

print(i)

a)

1 2 3

b)

i i i i

c)

i i i

d)

0 1 2

15.

What would be the output of the following code:

for i in range(3):

print(5)

a)

0 1 2

b)

3 3 3 3 3

c)

5 5 5

d)

0 1 2 3 4

16.

numbers = [2, 4, 6, 8]

for number in numbers:

print("hello!")

a)

2 hello! 4 hello! 6 hello! 8 hello!

b)

hello!

c)

2 4 6 8

d)

hello! hello! hello! hello!

17.

Which of the following for loops would print the following numbers?

3

5

7

9

a)

for i in range(3, 10, 2):

print(i)

b)

for i in range(3, 9, 2):

print(i)

c)

for i in range(9):

print(i)

d)

for i in range(3,9):

print(i)

18.

What would be the output of the following code:

for i in range(3):

print(i)

a)

1 2 3

b)

i i i i

c)

i i i

d)

0 1 2

19.

What would be the output of the following code:

for i in range(3):

print(5)

a)

0 1 2

b)

3 3 3 3 3

c)

5 5 5

d)

0 1 2 3 4