Countdown with holds
Every launch has a countdown, and most countdowns have planned holds: pauses at fixed points where the teams run their final checks. Sometimes a check fails, and the launch is scrubbed on the spot.
Print the countdown with its holds, then add the scrub.
Finish stage 1 to unlock this stage.
Count down from T-10 to T-0, one line per second, and add a hold line after every second that is in holds:
T-10 T-9 T-8 T-7 HOLD at T-7 T-6 T-5 T-4 T-3 HOLD at T-3 T-2 T-1 T-0
range(10, -1, -1) counts down to 0: the third number is the step, and the stop, -1, is one past the last number, as always. second in holds checks the list.
Finish stage 1 to unlock this stage.
Add scrub_at = None under holds. When the countdown reaches the second in scrub_at, print a scrub line and end the countdown there, even at a second with a hold. If it reaches the end, print Liftoff!:
T-10 T-9 T-8 T-7 HOLD at T-7 T-6 T-5 T-4 T-3 HOLD at T-3 T-2 T-1 T-0 Liftoff!
With scrub_at = 4, the countdown ends like this:
T-5 T-4 SCRUB at T-4
Check for the scrub before the hold, break after the scrub line, and use a flag to decide about Liftoff! after the loop.
Hints
For Loop with enumerate and range
# range() produces a run of numbers so you do not have to type them out
print(list(range(5)))
# One argument: starts at zero, stops before the number you gave
for orbit in range(3):
print("Orbit", orbit, "complete")
# Two arguments: a start and a stop. The stop is never included
for day in range(1, 6):
print("Flight day", day)
# Three arguments: the last one is the step, and it can go backwards
for altitude in range(100, 0, -25):
print(altitude, "km above the surface")
# enumerate() hands you the position and the item at the same time
checklist = ["hatch sealed", "fuel loaded", "guidance online", "range clear"]
for position, task in enumerate(checklist):
print(position, task)
# start=1 numbers things the way a human would
for position, task in enumerate(checklist, start=1):
print(f"Step {position}: {task}")
# Without enumerate you would be counting by hand
count = 0
for task in checklist:
count = count + 1
print("Items checked:", count)
Separate arguments with commas. They're passed on every Run as sys.argv[1:].