Space Python Loading Python…

Names with values

Write the codeEasy 2 stages

The telemetry decoder hands over each frame as separate lists: the sensor names in one, the readings in another, in matching order. The display needs them back together: each name next to its value.

Pair the lists up, add the units, and make sure the display notices when the lists don't match.

Print each sensor with its reading, going through both lists together:

ENG-1: 398.0
ENG-2: 412.5
TANK-1: 78.3
CABIN: 101.2

zip(sensors, readings) gives pairs: the first sensor with the first reading, and so on. Unpack each pair in the loop header.

Pair names with values
Works for any frame

Finish stage 1 to unlock this stage.

Add the units under the readings, and print each value with its unit:

units = ["C", "C", "%", "kPa"]
ENG-1: 398.0 C
ENG-2: 412.5 C
TANK-1: 78.3 %
CABIN: 101.2 kPa

zip() takes three lists as easily as two. But if one list is shorter, it stops early without a word, and a reading goes missing from the display. Before the loop, check that the three lengths are equal, and if they aren't, print a warning first:

Warning: 4 sensors, 3 readings, 4 units
ENG-1: 398.0 C
ENG-2: 412.5 C
TANK-1: 78.3 %

len(sensors) == len(readings) == len(units) checks all three at once.

Add the units
Warn about lists that don't match
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:].