Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
17 views3 pages

Python Worksheet 4 Loops - GDT

python activity

Uploaded by

bampoe-addov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Python Worksheet 4 Loops - GDT

python activity

Uploaded by

bampoe-addov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name:

Class: Date:

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

B for counter in range(20): 20

for counter in
C range(1,20):
19

for counter in
D range(3,23):
20
Name:
Class: Date:

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


A keep letting me add money While loop
to a piggy bank until I get to
£100.

I need a program that will


B keep letting me add a for loop
monthly payment for 12
months.

I need a guessing game


C program that will let me keep while loop
guessing until I get the right
answer.

I need a revision program


D that will run through revision for loop
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.

Answer:

piggy_bank = 0

while piggy_bank < 100:

amount = float(input("Enter amount to add to piggy bank: £"))


Name:
Class: Date:

piggy_bank += amount

print(f"Total savings: £{piggy_bank}")

print("Congratulations! You have saved £100.")

Copy and paste your working code here:

b. A program that will let me keep adding a monthly payment for 12 months.
Answer:

total_savings = 0

monthly_payment = float(input("Enter your monthly payment amount: £"))

for month in range(1, 13):

total_savings += monthly_payment

print(f"Month {month}: Total savings so far: £{total_savings}")

print("12 months completed! Final savings: £", total_savings)

You might also like