Space Python Loading Python…

Unreachable branch

Fix the codeEasy 3 stages

The engine mount sensor measured a vibration of 63, well over the critical limit of 50. The monitoring code reported WARN, and nobody shut the engine down.

Predict what the check prints, find out why the CRITICAL branch never runs, fix it, then write a chain with four levels.

Don't run the code yet. Read it and decide what it will print. Write your guess in prediction, at the top, between the quotes. Then run it and compare.

Any guess passes this stage: the point is to think before you run. After you check, you'll see your prediction next to what Python printed.

Go through the conditions in order, the way Python does, with the value 63.

Predict, then run
Leave the program as it is

Finish stage 1 to unlock this stage.

Investigate. Copy the condition Python checks first into checked_first, as text. Then think about any value at all: could it ever reach the CRITICAL branch in this order? Store True or False in critical_reachable.

Modify. Fix the order so readings over 50 report CRITICAL, readings over 30 WARN, and the rest OK. For 63 it must print:

CRITICAL
Find the dead branch
Fix the order

Finish stage 2 to unlock this stage.

The radiation monitor needs four levels, set by the flight surgeon:

below 30             NORMAL
from 30, below 100   ELEVATED
from 100, below 1000 HIGH
from 1000            SHELTER

Print the level for the reading. For 140 it's HIGH. Order the chain so every branch can be reached.

Print the level
Every branch can run
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:].