wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Looping Unit Test

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which of the following loops would print the following numbers.

a)

for i in range(5) :

print(i)

b)

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

c)

for i in range(6) :

print(i)

d)

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

2.

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)

3.

What is the value of num when this loop completes?

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?

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

It's still a nice day

It's still a nice day

b)

It's still a nice day

It's still a nice day

It's still a nice day

c)

It's still a nice day

It's still a nice day

It's still a nice day

It's still a nice day

It's still a nice day

d)

It's still a nice day

It's still a nice day

It's still a nice day

It's still a nice day

7.

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

a)

b)

c)

d)

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?

for j in range(2):

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

print(i)

a)

0

1

0

1

b)

0

2

0

2

c)

0

1

0

1

0

1

d)

1

2

1

2

1

2

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)

100

0

-75

-125

-150

b)

-150

c)

-175

d)

175

13.

What does this program print?

a)

0

1

2

b)

0

1

2

4

5

6

7

8

9

c)

1

2

3

4

5

6

7

8

9

d)

0

1

2

3

14.

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

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 a number less than 10, I want the loop to exit. Where should the break command be placed 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