wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

For Loop Python_2024

Total questions: 20

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 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

5.

#How many hallos will be printed?

a)

5

b)

None

c)

4

d)

6

6.

#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

7.
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
8.
What is iteration known as?
a)
Looping
b)
Crashing
c)
Repeating
9.
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
10.

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")

11.

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

12.

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

13.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

14.

Which of these will allow me to print all numbers from 0 to 4 ?

//0,1,2,3,4

a)

for x in range(4):

print(x)

b)

for x in range(0,4):

print(x)

c)

for x in range(1,5):

print(x)

d)

for x in range(5):

print(y)

15.

What will this code do?

a)

Print Numbers 1-11

b)

Print Numbers 1-10

c)

Print Numbers 2-10

d)

Print Error

16.

For i in range(6):

print('Happy Python')

How many times Happy Python will be printed?

a)

4

b)

5

c)

6

d)

7

17.

What are the syntax errors in this code?

a)

:

b)

Not indented

c)

Both options

18.

What is the output of range(1,10)

a)

0123456789

b)

123456789

c)

1 to 10

d)

012345

19.

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

word= "computer"  

for num in range(2,8):

      print(word)

a)

5

b)

6

c)

1

d)

0

20.

For i in range(4):

print('Happy Python')

How many times Happy Python will be printed?

a)

4

b)

5

c)

6

d)

7