Space Python Loading Python…

Safe mode

Write the codeMedium 2 stages

When something goes wrong far from Earth, a spacecraft can't wait for instructions. It switches into safe mode on its own: it turns off everything it doesn't need, points its solar panels at the Sun and waits for the ground to call.

Write the rule that decides when to enter safe mode, then make it report which rule fired, so the team on the ground knows where to start.

Enter safe mode when the battery is under 20% or contact has been lost for over 10 minutes. Either one is enough. With the battery at 18%:

Safe mode: ON

Join the two conditions with or. "Under 20" and "over 10" don't include 20 and 10 themselves.

Decide on safe mode
Either rule is enough

Finish stage 1 to unlock this stage.

The ground team needs to know why. Store each rule in a variable of its own, low_battery and lost_contact, then say which fired:

Safe mode: ON (battery and contact)
Safe mode: ON (battery)
Safe mode: ON (contact)
Safe mode: OFF

Check the case where both rules fired first. With the battery at 18% and contact fine, it prints the second line.

Name the rule
Right for every case
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

Logical Operators and, or, not

logical-operators-and-or-not.py
# Logical operators: and, or, not

fuel_percent = 85
crew_ready = True
weather = "clear"

# AND - both conditions must be true
if fuel_percent > 70 and crew_ready:
    print("Fuel and crew: GO")

# OR - at least one must be true
if weather == "clear" or weather == "overcast":
    print("Weather: GO")

# NOT - flips True to False and vice versa
abort_signal = False

if not abort_signal:
    print("No abort signal received")

# Combining all three in a launch decision
if fuel_percent > 70 and crew_ready and not abort_signal:
    print("ALL SYSTEMS GO - clear for launch!")
else:
    print("HOLD - check failed conditions")

# Try changing values above and run again
# What happens with fuel_percent = 50?
# What happens with abort_signal = True?
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:].