Loops
Python: Next steps
Python Worksheet 3 Pocket Money
Worksheet 4: Loops
1. Put a tick next to each print statement if you think the while() loop will run.
Put a cross next to each program if you think it won’t.
Program Will the loop run?
score = 200
A while score < 150:
print("...
score = 200
B while score > 150:
print("...
name = "Fred"
C while name != "Fred":
print("...
answer = 42
D while answer == 42:
print("...
2. How many times will each of these for() loops run?
How many times will
Program
the loop run?
A for counter in range(10):
B for counter in range(20):
for counter in
C range(1,20):
for counter in
D range(3,23):
Loops
Python: Next steps
3. For each situation, say whether it would be best to use a while() loop or a for() loop.
Program Which kind of loop?
I need a program that will
keep letting me add money
A to a piggy bank until I get to
£100.
I need a program that will
keep letting me add a
B monthly payment for 12
months.
I need a guessing game
program that will let me keep
C guessing until I get the right
answer.
I need a revision program
D that will run through revision
questions 4 times.
4. Try writing the code to create these loop statements:
a. A program that will keep letting me add money to a piggy bank untIl I get to
£100.
b. A program that will let me keep adding a monthly payment for 12 months.