Python Next Steps Homework 2 (1)
Python Next Steps Homework 2 (1)
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:
(a) Complete the value of each variable after the first pass through the loop
total: _______1____________
next: _________2__________
(b) Complete the value of each variable after the last pass through the loop [2]
total: _____7______________
next: ______8_____________
1
Homework 2: Loops
Python Next Steps
2
Homework 2: Loops
Python Next Steps
4. State when a programmer should use a for loop instead of a while loop [1]
When they want to control the amount of limes it loops
[Total 15 marks]