Python Next Steps Homework 2 Answers
Python Next Steps Homework 2 Answers
Homework 2: Loops
1. A computer game allows a player to repeat a level until they run out of lives.
Which two of the following loops would work correctly? [2]
⬨ while lives < 0:
while lives > 0:
⬨ while lives == 0:
while lives != 0:
1
Homework 2: Loops
Python Next Steps
4. State when a programmer should use a for loop instead of a while loop [1]
When the number of times to repeat is known
total = 0
for counter in range(7): (accept range(0,7))
papers = int(input(“How many papers delivered today? ”))
total = total + papers
print(“Total papers delivered =”, total)
[Total 15 marks]