Space Python Loading Python…

Alert level

Write the codeEasy 2 stages

The engine temperature sensors on Python One report a number, but the flight controllers need a decision: is it fine, does it need watching, or does the engine have to be shut down?

Turn the reading into an alert level with two thresholds, then build the status line the console shows.

Print OK, WARN or CRITICAL for the temperature. From 400 °C it's WARN, from 450 °C CRITICAL, anything lower is OK. For 412.5:

WARN

Check the most serious level first: if for CRITICAL, elif for WARN, else for OK. "From 400" includes 400 itself, so use >=. Indent each branch's line by four spaces.

Print the alert level
Right at every level

Finish stage 1 to unlock this stage.

The console shows the sensor, the reading and the level on one line. Add sensor = "ENG-2" under the temperature, store the level in a variable in each branch instead of printing it, and print once at the end:

ENG-2: 412.5 °C, WARN

Each branch sets level, and the single print() after the chain uses it.

Print the status line
Right for any reading
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:].