Space Python Loading Python…

Check every reading

Write the codeEasy 2 stages

In "Alert level" you turned one engine temperature into OK, WARN or CRITICAL. Real telemetry doesn't arrive one number at a time: after each pass the ground station gets a whole list of readings, and every one of them needs the same check.

Run the check over the whole list, then add a summary the flight director can read at a glance.

The check from "Alert level" handles one temperature. Make it check every temperature in temperatures_c and print each one with its level:

398.0 °C: OK
412.5 °C: WARN
455.2 °C: CRITICAL
401.7 °C: WARN
450.0 °C: CRITICAL
399.9 °C: OK

Replace the line temperature_c = 412.5 with for temperature_c in temperatures_c:, then indent the whole check and the print under it, so they run once for each temperature.

Check every reading
Works for any readings

Finish stage 1 to unlock this stage.

After the list, print a summary: how many readings there were, and how many were WARN and CRITICAL:

398.0 °C: OK
412.5 °C: WARN
455.2 °C: CRITICAL
401.7 °C: WARN
450.0 °C: CRITICAL
399.9 °C: OK
Readings: 6, WARN: 2, CRITICAL: 2

Set warn_count = 0 and critical_count = 0 before the loop, add 1 to the right one inside the WARN and CRITICAL branches, and print the summary after the loop, at the left edge.

Count the alerts
Works for any readings
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:].