Space Python Loading Python…

Numbered checklist

Write the codeEasy 2 stages

Before every flight the crew works through the pre-flight checklist, item by item, and calls out each number as they go. The checklist is stored as a list, and the screen in the cockpit shows it numbered, starting from 1.

Print the numbered checklist, then show which items are already done.

Print the checklist numbered from 1, one item per line:

1. Seal the hatch
2. Check cabin pressure
3. Arm the abort system
4. Switch to internal power
5. Get a go from Mission Control

enumerate(checklist, start=1) gives pairs of a number and an item. Unpack them in the loop: for number, item in enumerate(checklist, start=1):.

Number the checklist
Works for any checklist

Finish stage 1 to unlock this stage.

The crew has done the first two items. Add completed = 2 under the list, then show done items with [x] and the rest with [ ]:

[x] 1. Seal the hatch
[x] 2. Check cabin pressure
[ ] 3. Arm the abort system
[ ] 4. Switch to internal power
[ ] 5. Get a go from Mission Control

Inside the loop, compare number with completed to choose the box.

Tick off done items
Works at any point
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

For Loop with enumerate and range

for-loop-enumerate-range.py
# 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)
Open the full example
script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].