Font size
WorksheetsWhile Loops
Total questions: 87
Worksheet time: 1hrs 27mins
0 1 2
012
0
1
2
0 1 2 3
0
1
2
3
l e t t e r s
letters
0 1 2 3 4 5 6
l e t t e r
letter
vortex vortex vortex vortex
vortex
vortex
vortex
vortex
vortex, vortex, vortex, vortex
0 1 2 3
0 1 2 3 4
6
0
1
3
6
0
1
2
3
5
3
2
16
32
2
4
8
16
2
4
8
16
32
cat
cat
cat
cat
cat
catcatcatcatcat
cat cat cat cat cat
5
4
3
2
1
0
count
count artistic
1
8
7
10
2
3
8
an error will be received
0 1 2 3 4
0 1 2 3 4 5
5
4
this won't work properly, infinite loop
0 2 4 6 8 10
p n e e e n
10
n
0
b = = k = = p = r
= e e = e e = e =
= = = =
e e e e e
b k p r
$ $ $ $ $
$ $ $ $
$ $ $
$ $
$ $ $ $ $
$ $
$ $ $ $
$ $ $ $ $
$ $
20
25
21
infinite loop
sum: 39
sum: 38
sum: 24
sum: 57
11
7 8 9 10 11
12
7 8 9 10 11 12
25
35
26
46
0
3 5 7 9
24
error
For the code shown, what will happen?
It will print all the numbers from 0 to 11
It will print all the numbers from 0 to 11 in increments of 3
Infinite loop
It will not run (Syntax error)
A while loop is used when
You know how many times you are going to loop
You want to loop for an unknown number of times, and possibly forever
You only want to run the code in the loop once
You see the word while in the problem description
What is the final value of n?
(a)
Why is iteration important?
It determines the order in which instructions are carried out
It allows code to be simplified by removing duplicated steps into a block that can be executed many times
It allows multiple paths through a program
It ensures the code works correctly
What is the output of this code?
It would print 'So good to see you' infinite number of times
There would be no output
It would print an error message.
It would print 'Enter correct code'.
The condition for a while loop to continue could include which of the following?
While something equals something
While something is True
While something is greater than something
All of these
What is the final value of the variable 'number'?
(a)
What is the output?
5
4
3
2
1
5 4 3 2 1
4
3
2
1
0
4 3 2 1 0
To increment means to
increase the value of a variable
decrease the value of a variable
add 1 to the variable
subtract 1 from the variable
What is the output?
12 9 6 3 0
0 3 6 9 12
0 3 6 9
9 6 3 0
A counter is (check ALL that apply)
A variable used in a loop to count the number of times something happened
usually initialised to zero
usually incremented inside the loop
a person with a pen and paper
used only outside of the loop
What is the output?
0 5 10
5 10
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
12 7 2
What is the output?
12 17 22
12
5
5 10
What is the output?
Hello world
Hello there
Error
Hello there
Hello there
Hello there
Hello there
Hello there
...(forever)
What is the output?
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
Hello world!
Hello world!
break
Error
What is the output?
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
Hello world!
Hello world!
break
Error
What is the output is the user types "Python"?
Welcome
Try again!
Error
Enter your password
What will this code output?
Nothing
1
4
7
Bye
Jon
Jon
Bye
Jon
Jon
Jon
Bye
Jon
Jon
Jon
Jon
Jon
Jon
Bye
What will be the output of this code?
This loop will not run
An infinite loop
It'll print all numbers from 1-9
It'll print all numbers from 1-10
What will happen if the user enters the sequence (each time through the loop)
2, 5, 3, q
Loop finishes and prints 10
Loop never ends
Program throws a ValueError when calling the int() function
Program asks user to enter another num
4
3
2
1
3
2
1
0
4
3
2
1
3
2
1
0
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
break
False
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
What is a Count-Controlled loop?
for loop
while loop
A count controlled loop will..
Repeat code until a condition is met
Repeat code a specific amount of times
Repeat code a random amount of times
None of the above
What will this code do?
Print Numbers 1-11
Print Numbers 1-10
Print Numbers 2-10
Print Error
Which of these is NOT a loop in python?
for loop
while loop
nested loop
if loop
What will be the output of this code?
1,2,3,4,5,6,7,8,9,10,11,12
0,2,4,6,8,10
2,4,6,8,10,12
2,4,6,8,10
What does the '#' allow you to do?
Repeat code
Comment on code
Print code
End code
Which of these will allow me to count from 0-20 in steps of 5?
for x in range(0,20):
print(x)
while x = (0,20,5):
print(x)
for x in range(0,21,5):
print(x)
for x in range(0,21,5):
print(y)
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?
The last line should be outside the loop
A For loop needed to be used
Which type of data will be stored?
String
Integer
Float
Boolean
Which type of data will be stored?
String
Integer
Float
Boolean
From the line of code below match each keyword to its programming defintion
pin = int(input("Please enter the pin number")
pin
variable name
=
assignment
int
declared data type
"Please enter the pin number"
prompt seen on screen
Match the following programming constructs to the example piece of code
print ("I ")
print ("Will ")
print ("Pass!")
Sequence
balance = 0
if balance >5:
print ("you can make this purchase")
else:
print (" insufficient funds")
Selection
target = int(input())
while target <50:
print ("You will need to increase the target score")
Condition based
Iteration
number = 10
for X in range (number):
print (X*number
Count based Iteration
I feel confident in creating variables
True
False
I feel confident in creating selection statements
(If, elif & else)
True
False
I feel confident in creating loops in a program
True
False
4
3
2
1
3
2
1
0
4
3
2
1
3
2
1
0
4
3
2
1
3
2
1
0
8
6
4
2
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
break
False
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
