[go: up one dir, main page]

0% found this document useful (0 votes)
31 views2 pages

Python Worksheet 4 Loops

The document provides exercises related to loops in Python, focusing on while() and for() loops. It includes tasks for determining if certain loops will run, counting iterations, and deciding which type of loop to use for specific scenarios. Additionally, it prompts users to write code for given loop statements.

Uploaded by

greeley.grant
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)
31 views2 pages

Python Worksheet 4 Loops

The document provides exercises related to loops in Python, focusing on while() and for() loops. It includes tasks for determining if certain loops will run, counting iterations, and deciding which type of loop to use for specific scenarios. Additionally, it prompts users to write code for given loop statements.

Uploaded by

greeley.grant
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/ 2

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.

You might also like