
Checkpoint
Checkpoint: Night Patrol
Night falls on Emberreach, and Pip patrols the harbour with a lantern. Each patrol hour burns 2 oil. Every 3rd hour, Pip rests instead and uses no oil. If there are fewer than 2 oil left, the patrol must end.
This checkpoint uses the whole chapter: for and range,
%, continue, break and adding up as you go.
Assignment
Inside the loop, do these checks in this order:
- If
houris a multiple of 3 (hour % 3 == 0), skip this hour withcontinue. - If
oilis less than2, printOut of oil at hour 8!(with the real hour, using an f-string). Then stop the loop withbreak. - Otherwise, take
2fromoil, add1topatrols, and printHour 1: patrol(with the real hour).
Keep the last print line. With the starting values, the output should be:
Hour 1: patrol
Hour 2: patrol
Hour 4: patrol
Hour 5: patrol
Hour 7: patrol
Out of oil at hour 8!
Patrols: 5, oil left: 1Inside the loop, do these checks in this order:
- If
houris a multiple of 3 (hour % 3 == 0), skip this hour withcontinue. - If
oilis less than2, printOut of oil at hour 8!(with the real hour, using an f-string). Then stop the loop withbreak. - Otherwise, take
2fromoil, add1topatrols, and printHour 1: patrol(with the real hour).
Keep the last print line. With the starting values, the output should be:
Hour 1: patrol
Hour 2: patrol
Hour 4: patrol
Hour 5: patrol
Hour 7: patrol
Out of oil at hour 8!
Patrols: 5, oil left: 1main.py Python sleeping
Press Run to try your code, then Check to test it.