Space Python Loading Python…

Telemetry report

Write the codeMedium 2 stages

The ground station no longer gets one reading at a time: the feed now delivers a block of lines every second. The flight controllers want them as a report they can scan at a glance, not as raw comma-separated text.

Extend your parser from "Parse a telemetry line" to read the whole block, then lay it out as a table with aligned columns.

The starter code has the feed and your parser from "Parse a telemetry line", which reads one line. Replace the parser so it reads all three lines of the feed and prints each reading on one row: the time of day, the sensor, the value and the unit.

09:30:05 ENG-2 412.5 C
09:30:06 CAB-1 101.3 kPa
09:30:07 BAT-3 87.2 %

feed.split("\n") splits the feed into its lines, and each line splits at the commas as before. The time of day is [11:19] of the timestamp. print() puts a space between its values.

Print every reading
Works for any feed

Finish stage 1 to unlock this stage.

Now make it a report: a header row and columns that line up, with the values right-aligned to one decimal place.

TIME      SENSOR     VALUE  UNIT
09:30:05  ENG-2      412.5  C
09:30:06  CAB-1      101.3  kPa
09:30:07  BAT-3       87.2  %

Use widths as in "Aligned status board": the time column is 10 characters wide and the sensor column 9, both left-aligned; the value is right-aligned in 7, as :>7.1f, so the decimal points line up; then two spaces and the unit. The header uses the same widths.

Print the report
Lines up 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:].