wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Lesson 5 Looping Quiz

Total questions: 15

Worksheet time: 17mins

Name
Class
Date
1.

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


0

1

2

3

4

5

a)
b)
c)
d)
2.

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


3

5

7

9

a)
b)
c)
d)
3.

What is the value of num when this loop completes?

num = 0

a)

2

b)

8

c)

12

d)

20

4.

Which of the following for loops will give the same values for i as the loop below?


for i in range(10):

a)

for i in range(11, 0):

b)

for i in range(10, 0, -1):

c)

for i in range(0, 10):

d)

for i in range(0, 11, 1):

5.

Three of the for loops below will provide identical values for i.

Which for loop will provide values that do not match the others?

a)

for i in range(0, 5):

b)

for i in range(5):

c)

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

d)

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

6.

What does this program print?

a)
b)
c)
d)
7.

Which of the following while loops would continue to loop as long as num has values between the range of 3-12, exclusive?

a)

while num > 12 and num < 3:

# do something with num

b)

while num < 12 or num < 3:

# do something with num

c)

while num <= 12 and num >= 3:

# do something with num

d)

while num < 12 and num > 3:

# do something with num

8.

Which of the following while loops will cause an infinite loop?

a)
b)
c)
d)
9.

When would a while loop be a better control structure to use than a for loop?

a)

When you need to repeat multiple commands

b)

When you need to repeat something 5 times

c)

When you don’t know how many times something will need to repeat

d)

When the user is inputting how many times to repeat something

10.

What will be printed to the screen when this program is run?

a)
b)
c)
d)
11.

What is the value of sum when this loop completes?

a)

8

b)

9

c)

20

d)

0

12.

What will be printed to the screen when this program is run?

a)
b)
c)
d)
13.

What does this program print?

a)
b)
c)
d)
14.

What is the benefit of using the break command as in the program above?

a)

The user can enter as many answers as they want

b)

The program will break out of the loop as soon as the user enters the magic_number

c)

The loop will prompt the user to enter a number no matter what input they give

d)

The loop will give the magic_number after a certain number of tries

15.

If the user enters ‘4’, I want the loop to exit. Where should the break command be placed in order to end the loop when the user enters this value?

a)

On line 3

b)

On line 5

c)

On line 7

d)

On line 9