wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

While Loops

Total questions: 87

Worksheet time: 1hrs 27mins

Name
Class
Date
1.
a)

0 1 2

b)

012

c)

0

1

2

d)

0 1 2 3

e)

0

1

2

3

2.
a)

l e t t e r s

b)

letters

c)

0 1 2 3 4 5 6

d)

l e t t e r

e)

letter

3.
a)

vortex vortex vortex vortex

b)

vortex

vortex

vortex

vortex

c)

vortex, vortex, vortex, vortex

d)

0 1 2 3

e)

0 1 2 3 4

4.
a)

6

b)

0

1

3

6

c)

0

1

2

3

d)

5

e)

3

5.
a)

2

b)

16

c)

32

d)

2

4

8

16

e)

2

4

8

16

32

6.
a)

cat

cat

cat

cat

cat

b)

catcatcatcatcat

c)

cat cat cat cat cat

d)

5

4

3

2

1

e)

0

7.
a)

count

b)

count artistic

c)

1

d)

8

e)

7

8.
a)

10

b)

2

c)

3

d)

8

e)

an error will be received

9.
a)

0 1 2 3 4

b)

0 1 2 3 4 5

c)

5

d)

4

e)

this won't work properly, infinite loop

10.
a)

0 2 4 6 8 10

b)

p n e e e n

c)

10

d)

n

e)

0

11.
a)

b = = k = = p = r

b)

= e e = e e = e =

c)

= = = =

d)

e e e e e

e)

b k p r

12.
a)

$ $ $ $ $

$ $ $ $

$ $ $

$ $

b)

$ $ $ $ $

c)

$ $

d)

$ $ $ $

e)

$ $ $ $ $

$ $

13.
a)

20

b)

25

c)

21

d)

infinite loop

14.
a)

sum: 39

b)

sum: 38

c)

sum: 24

d)

sum: 57

15.
a)

11

b)

7 8 9 10 11

c)

12

d)

7 8 9 10 11 12

16.
a)

25

b)

35

c)

26

d)

46

17.
a)

0

b)

3 5 7 9

c)

24

d)

error

18.

For the code shown, what will happen?

a)

It will print all the numbers from 0 to 11

b)

It will print all the numbers from 0 to 11 in increments of 3

c)

Infinite loop

d)

It will not run (Syntax error)

19.

A while loop is used when

a)

You know how many times you are going to loop

b)

You want to loop for an unknown number of times, and possibly forever

c)

You only want to run the code in the loop once

d)

You see the word while in the problem description

20.

What is the final value of n?

(a)  

21.

Why is iteration important?

a)

It determines the order in which instructions are carried out

b)

It allows code to be simplified by removing duplicated steps into a block that can be executed many times

c)

It allows multiple paths through a program

d)

It ensures the code works correctly

22.

What is the output of this code?

a)

It would print 'So good to see you' infinite number of times

b)

There would be no output

c)

It would print an error message.

d)

It would print 'Enter correct code'.

23.

The condition for a while loop to continue could include which of the following?

a)

While something equals something

b)

While something is True

c)

While something is greater than something

d)

All of these

24.

What is the final value of the variable 'number'?

(a)  

25.

What is the output?

a)

5

4

3

2

1

b)

5 4 3 2 1

c)

4

3

2

1

0

d)

4 3 2 1 0

26.

To increment means to

a)

increase the value of a variable

b)

decrease the value of a variable

c)

add 1 to the variable

d)

subtract 1 from the variable

27.

What is the output?

a)

12 9 6 3 0

b)

0 3 6 9 12

c)

0 3 6 9

d)

9 6 3 0

28.

A counter is (check ALL that apply)

a)

A variable used in a loop to count the number of times something happened

b)

usually initialised to zero

c)

usually incremented inside the loop

d)

a person with a pen and paper

e)

used only outside of the loop

29.

What is the output?

a)

0 5 10

b)

5 10

c)

0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140......etc

d)

12 7 2

30.

What is the output?

a)

12 17 22

b)

12

c)

5

d)

5 10

31.

What is the output?

a)

Hello world

b)

Hello there

c)

Error

d)

Hello there

Hello there

Hello there

Hello there

Hello there

...(forever)

32.

What is the output?

a)

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

(repeated continuously)

b)

Hello world!

c)

Hello world!

break

d)

Error

33.

What is the output?

a)

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

(repeated continuously)

b)

Hello world!

c)

Hello world!

break

d)

Error

34.

What is the output is the user types "Python"?

a)

Welcome

b)

Try again!

c)

Error

d)

Enter your password

35.

What will this code output?

a)

Nothing

b)

1

4

7

Bye

c)

Jon

Jon

Bye

d)

Jon

Jon

Jon

Bye

e)

Jon

Jon

Jon

Jon

Jon

Jon

Bye

36.

What will be the output of this code?

a)

This loop will not run

b)

An infinite loop

c)

It'll print all numbers from 1-9

d)

It'll print all numbers from 1-10

37.

What will happen if the user enters the sequence (each time through the loop)

2, 5, 3, q

a)

Loop finishes and prints 10

b)

Loop never ends

c)

Program throws a ValueError when calling the int() function

d)

Program asks user to enter another num

38.
In programming, what is iteration?
a)
The repetition of steps within a program
b)
The order in which instructions are carried out
c)
A decision point in a program
d)
Testing a program to make sure it works
39.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
d)
It ensures the code works correctly
40.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
41.
Which type of loop iterates until instructed otherwise?
a)
FOR loop
b)
A count-controlled loop
c)
Repeat-once loop
d)
WHILE loop
42.
The condition for a while loop to continue could include which of the following?
a)
While something equals something
b)
While something is greater than something
c)
While something is True
d)
All of these
43.
Which of the following symbols is used in Python to mean "Equal to"?
a)
=
b)
!=
c)
==
d)
>=
44.
Which of the following symbols is used in Python to mean "Not equal to"?
a)
==
b)
!=
c)
<>
d)
><
45.
Which of the following symbols is used in Python to mean "Greater than or equal to"?
a)
<=
b)
>>
c)
>=
d)
=>
46.
a)
5
4
3
2
1
b)
4
3
2
1
0
c)
5  4  3  2  1
d)
4  3  2  1  0
47.
a)
5
4
3
2
1
b)
4
3
2
1
0
c)
5  4  3  2  1
d)
4  3  2  1  0
48.
a)
Hello world!
b)
Hello world
c)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
d)
Error
49.
a)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
b)
Hello world!
c)
Hello world!
break              
d)
Error
50.
a)
Hello world!
b)
Error
c)
Hello world!
False
d)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
51.
a)
Welcome
b)
Try again!
c)
Error
d)
Enter your password
52.

What is a Count-Controlled loop?

a)

for loop

b)

while loop

53.

A count controlled loop will..

a)

Repeat code until a condition is met

b)

Repeat code a specific amount of times

c)

Repeat code a random amount of times

d)

None of the above

54.

What will this code do?

a)

Print Numbers 1-11

b)

Print Numbers 1-10

c)

Print Numbers 2-10

d)

Print Error

55.

Which of these is NOT a loop in python?

a)

for loop

b)

while loop

c)

nested loop

d)

if loop

56.

What will be the output of this code?

a)

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

b)

0,2,4,6,8,10

c)

2,4,6,8,10,12

d)

2,4,6,8,10

57.

What does the '#' allow you to do?

a)

Repeat code

b)

Comment on code

c)

Print code

d)

End code

58.

Which of these will allow me to count from 0-20 in steps of 5?

a)

for x in range(0,20):

print(x)

b)

while x = (0,20,5):

print(x)

c)

for x in range(0,21,5):

print(x)

d)

for x in range(0,21,5):

print(y)

59.
Which loop is most appropriate to use if I need to continuously check for a correct password?
a)
FOR loop
b)
WHILE LOOP
60.

I want to print "Password matched" if the user enters the correct password, otherwise allow them to try again. What is wrong with the code above?

a)

The last line should be outside the loop

b)

A For loop needed to be used

61.

Which type of data will be stored?

a)

String

b)

Integer

c)

Float

d)

Boolean

62.

Which type of data will be stored?

a)

String

b)

Integer

c)

Float

d)

Boolean

63.

From the line of code below match each keyword to its programming defintion

pin = int(input("Please enter the pin number")

a)

pin

1.

variable name

b)

=

2.

assignment

c)

int

3.

declared data type

d)

"Please enter the pin number"

4.

prompt seen on screen

64.

Match the following programming constructs to the example piece of code

a)

print ("I ")

print ("Will ")

print ("Pass!")

1.

Sequence

b)

balance = 0

if balance >5:

print ("you can make this purchase")

else:

print (" insufficient funds")

2.

Selection

c)

target = int(input())

while target <50:

print ("You will need to increase the target score")

3.

Condition based

Iteration

d)

number = 10

for X in range (number):

print (X*number

4.

Count based Iteration

65.

I feel confident in creating variables

a)

True

b)

False

66.

I feel confident in creating selection statements

(If, elif & else)

a)

True

b)

False

67.

I feel confident in creating loops in a program

a)

True

b)

False

68.
In programming, what is iteration?
a)
The repetition of steps within a program
b)
The order in which instructions are carried out
c)
A decision point in a program
d)
Testing a program to make sure it works
69.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
d)
It ensures the code works correctly
70.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
71.
Which type of loop iterates until instructed otherwise?
a)
FOR loop
b)
A count-controlled loop
c)
Repeat-once loop
d)
WHILE loop
72.
The condition for a while loop to continue could include which of the following?
a)
While something equals something
b)
While something is greater than something
c)
While something is True
d)
All of these
73.
Which of the following symbols is used in Python to mean "Equal to"?
a)
=
b)
!=
c)
==
d)
>=
74.
Which of the following symbols is used in Python to mean "Not equal to"?
a)
==
b)
!=
c)
<>
d)
><
75.
Which of the following symbols is used in Python to mean "Greater than or equal to"?
a)
<=
b)
>>
c)
>=
d)
=>
76.
a)
5
4
3
2
1
b)
4
3
2
1
0
c)
5  4  3  2  1
d)
4  3  2  1  0
77.
a)
5
4
3
2
1
b)
4
3
2
1
0
c)
5  4  3  2  1
d)
4  3  2  1  0
78.
a)
5
4
3
2
1
b)
5  4  3  2  1
c)
4
3
2
1
0
d)
4  3  2  1  0
79.
a)
10  8  6  4  2
b)
10
8
6
4
2
c)
2  4  6  8  10
d)
10  9  8  7  6  5  4  3  2  1
80.
a)
12  9  6  3  0
b)
0  3  6  9  12
c)
9  6  3  0
d)
0  3  6  9
81.
a)
0  5  10
b)
5  10
c)
0  5  10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95  100  105  110  115  120  125  130  135  140......etc
d)
12  7  2
82.
a)
12  17   22
b)
5
c)
12
d)
5  10
83.
a)
Hello world!
b)
Hello world
c)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
d)
Error
84.
a)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
b)
Hello world!
c)
Hello world!
break              
d)
Error
85.
Which of the following symbols is used in Python to mean "Less than or equal to"?
a)
<<
b)
=<
c)
<=
d)
!=
86.
a)
Hello world!
b)
Error
c)
Hello world!
False
d)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
87.
a)
Welcome
b)
Try again!
c)
Error
d)
Enter your password