Space Python Loading Python…

Missing reading

Write the codeMedium 2 stages

Sensors don't always answer. When one misses a reading, the driver hands your alert check None instead of a number, and the check from "Alert level" stops with a TypeError in the middle of a pass.

Extend your check so a missing reading is reported, not crashed on, then handle missing values in the telemetry feed as well.

The starter code is your check from "Alert level", but this time the sensor didn't answer and temperature_c is None. Run it: comparing None with a number stops with a TypeError. Check for None first, so it prints:

ENG-2: NO DATA

Use temperature_c is None, and move the existing chain and its print into the else, indented by four more spaces. Don't use if not temperature_c: 0 °C is a real reading.

Report the missing reading
Real readings still work

Finish stage 1 to unlock this stage.

Readings now come from the telemetry feed, and a missing value shows up as an empty field: two commas with nothing between them. The starter code parses the line and stops with a ValueError, because float("") makes no sense. Check the field before converting it:

ENG-2: NO DATA

Strip the field first, so a field with only a space counts as empty too, then compare it with "". Convert with float() only in the else.

Report the empty field
Right for any line
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

If-elif-else Statement

if-elif-else-statement.py
# Oxygen level on a space station
oxygen = 19.5

if oxygen >= 23:
    status = "Warning: fire risk"
elif oxygen >= 19.5:
    status = "Normal"
elif oxygen >= 16:
    status = "Low"
else:
    status = "Critical"

print(status)

# Signal delay from a deep space probe
delay = 14.0  # minutes

if delay < 1.3:
    location = "Near the Moon"
elif delay < 5:
    location = "Inner solar system"
elif delay < 25:
    location = "Outer planets region"
else:
    location = "Deep space"

print(f"Delay: {delay} min - {location}")
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:].