Settings with defaults
The mission dashboard has a default for every setting, and each user's profile stores only what they have changed. When a user opens the dashboard, the two have to be combined: their values where they set one, the default everywhere else.
Merge the settings, then make the merge reject settings that don't exist.
Finish stage 1 to unlock this stage.
Build settings: the defaults, with the user's own values on top. Leave DEFAULTS unchanged, since every user shares it. Then print every setting:
units: imperial language: en telemetry_rate_hz: 10 dark_mode: True alerts: all
DEFAULTS.copy() makes a separate dict, and settings.update(user_settings) overwrites the keys the user set.
Finish stage 1 to unlock this stage.
A user's profile has a typo: "dark_mod". With update() it becomes a sixth setting that nothing reads. Copy only the keys that exist in DEFAULTS, and report the others before the settings:
Unknown setting ignored: dark_mod units: imperial language: en telemetry_rate_hz: 10 dark_mode: True alerts: all
Loop over user_settings.items() and check each key with in DEFAULTS.
Hints
Modifying Dictionaries
# A mission record that changes as the mission goes on
parker = {
"name": "Parker Solar Probe",
"launched": 2018,
"orbits": 20,
"status": "cruising",
}
# Assign to a key that does not exist yet and it gets added
parker["closest_km"] = 6100000
print(parker)
# The same syntax on an existing key overwrites the old value
parker["status"] = "perihelion pass"
parker["orbits"] = 21
print("Status:", parker["status"], "after", parker["orbits"], "orbits")
# update() applies several changes in one go
parker.update({"speed_kmh": 692000, "status": "record holder"})
print("Speed:", parker["speed_kmh"], "km/h")
# pop() removes a key and hands the value back to you
old_status = parker.pop("status")
print("Removed status was:", old_status)
# del removes a key without giving anything back
del parker["launched"]
print(parker)
# setdefault() only fills in a key that is missing
parker.setdefault("agency", "NASA")
parker.setdefault("name", "Something Else")
print("Name:", parker["name"], "| Agency:", parker["agency"])
Separate arguments with commas. They're passed on every Run as sys.argv[1:].