Space Python Loading Python…

Parse the whole feed

Write the codeEasy 2 stages

In "Parse a telemetry line" you split one reading into its fields. The ground station receives the feed as one block of text, one reading per line, and a parser has to handle every line the same way.

Loop over the lines, split each one, and print what the flight controllers need.

Go through the feed line by line, split each line at the commas, and print the sensor, the value and the unit:

ENG-2: 412.5 C
TANK-1: 78.3 %
CABIN: 101.2 kPa
ENG-2: 415.0 C

feed.splitlines() gives a list with one string per line. Inside the loop, line.split(",") gives the four fields, as in "Parse a telemetry line".

Parse every line
Works for any feed

Finish stage 1 to unlock this stage.

Unpack the four fields into names, as in "Manifest line", and start each line with the clock time from the timestamp:

09:30:05 ENG-2: 412.5 C
09:30:05 TANK-1: 78.3 %
09:30:10 CABIN: 101.2 kPa
09:30:10 ENG-2: 415.0 C

timestamp, sensor, value, unit = line.split(",") names the fields. The clock time is characters 11 to 18 of the timestamp: timestamp[11:19].

Show the time
Works for any feed
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 Basics

for-loop-basics.py
# A for loop visits every item in a collection, one at a time
cargo = ["water", "food", "spare parts", "experiments"]

for item in cargo:
    print("Loading:", item)

print("Hold sealed")

# The loop body can do real work, not just print
masses_kg = [820, 640, 310, 175]
total = 0
for mass in masses_kg:
    total = total + mass
print("Total cargo:", total, "kg")

# A tuple of pairs unpacks straight into two variables
manifest = (("water", 820), ("food", 640), ("experiments", 175))
for name, mass in manifest:
    print(f"{name}: {mass} kg")

# A string is a collection too, one character at a time
for letter in "CYGNUS":
    print(letter, end=" ")
print()

# A set works as well, but the order is never promised
for module in {"Unity", "Harmony", "Destiny"}:
    print("Docking check:", module)
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:].