Space Python Loading Python…

Aligned status board

Write the codeMedium 3 stages

Before launch, the flight director reads a status board: every system and its state, one per line. Because the names are all different lengths, the states end up scattered across the screen, and a HOLD is easy to miss.

Line the states up in a column. Format specs can give each value a fixed width, so the next column always starts in the same place, whatever the name.

The starter code prints the board, but HOLD sits further left than the GO above it. Make the states start in the same column:

Propulsion  GO
Navigation  GO
Comms       HOLD

Give each name a width of 12 characters, aligned left: {system1:<12}. Python fills the rest with spaces, so remove the space you typed between the two values.

Line up the states
Hold the column for any name

Finish stage 1 to unlock this stage.

Add a header row, so people know what the columns are:

SYSTEM      STATE
Propulsion  GO
Navigation  GO
Comms       HOLD

Format specs work on any value, including text you write straight into the braces: {'SYSTEM':<12}. Use the other kind of quotes inside, so they don't end the f-string.

Add the header row
Hold the column for any name

Finish stage 2 to unlock this stage.

The board gets a third column: each system's temperature in °C. Numbers read best aligned to the right, so their decimal points line up. Give the states a width of 6, and make the temperature column 7 characters wide, aligned right, with one decimal place. Align its header the same way:

SYSTEM      STATE    TEMP
Propulsion  GO      412.5
Navigation  GO       21.0
Comms       HOLD    -40.3

One spec can combine alignment, width and decimal places: {temp1:>7.1f}.

Add the temperature column
Hold the columns for any values
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

Text Formatting with f-strings

text-formatting-f-strings.py
# F-strings - modern text formatting
astronaut = "John Smith"
mission = "Mars Explorer"
days_in_space = 180

print(f"Astronaut: {astronaut}")
print(f"Mission: {mission}")
print(f"Duration: {days_in_space} days")

# We can also do calculations
print(f"That is {days_in_space / 30:.1f} months")
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:].