Space Python Loading Python…

Airlock permissions

Write the codeMedium 2 stages

Nobody operates an airlock on trust. Each action needs a set of permissions, from basic operator training to the commander's approval for opening the outer hatch, and the airlock's control panel checks them before it does anything.

Check one action for one crew member, then the whole list of airlock actions.

Check that the crew member holds every permission in needed. If not, print what is missing, sorted:

Kowalska can't depressurise the airlock: missing eva_certified

needed <= granted is True when every item of needed is in granted. needed - granted is what's missing.

Check the permissions
Works for anyone

Finish stage 1 to unlock this stage.

The control panel shows every airlock action at once. ACTIONS maps each action to the permissions it needs. Print the crew member's name, then each action: allowed, or what is missing for it:

Kowalska:
  depressurise the airlock: allowed
  open the outer hatch: missing commander_approval, eva_certified
  repressurise the airlock: allowed

Loop over ACTIONS.items(); for each action, needed - granted is empty when the action is allowed.

Check every action
Works for anyone
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

Comparing Sets

comparing-sets.py
# Instruments this experiment cannot run without
required = {"camera", "spectrometer", "drill"}

# What our lander actually carries
onboard = {"camera", "spectrometer", "drill", "magnetometer", "seismometer"}

# What a second lander carries
backup = {"radar", "weather station"}

# issubset(): is everything in required also in onboard?
print("Experiment possible?", required.issubset(onboard))

# issuperset(): the same relationship, asked from the other side
print("Lander covers it?", onboard.issuperset(required))

# The operators say the same thing in fewer characters
print(required <= onboard, onboard >= required)

# One missing instrument is enough to break it
wishlist = {"camera", "drill", "laser"}
print("Wishlist possible?", wishlist.issubset(onboard))
print("Still missing:", wishlist - onboard)

# isdisjoint(): do the two landers share anything at all?
print("Fully complementary?", onboard.isdisjoint(backup))

# Every set is a subset of itself, but never a proper subset
print(onboard.issubset(onboard), onboard < onboard)

# And an empty set fits inside absolutely everything
print(set().issubset(onboard))
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:].