Missing field
The launch board shows each launch with its pad. It worked for weeks, until the API sent a launch that hadn't been given a pad yet. Instead of a board with one blank, the operators got an error and no board at all.
Predict what happens, find out what the dict really holds, fix it, then build a board that copes with any missing field.
Finish stage 1 to unlock this stage.
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.
Look at the keys the dict really has.
This program crashes, and a program that crashes can't be checked. After you run it and see the error, put a # in front of the last print line, then check: you'll see your prediction next to what the original line did.
Finish stage 1 to unlock this stage.
Investigate. Check whether "pad" is one of the keys with "pad" in launch, and store True or False in pad_is_key. Then print launch.get("pad") and store what it gives back, as text, in get_gives. Remove any lines you added before you check.
Modify. When there is no pad, print TBD instead of stopping. It must print:
Launch: Kestrel-7 Pad: TBD
Finish stage 2 to unlock this stage.
Print every launch with its provider and pad, using a default for whichever is missing:
Lumen-3: JAXA, Tanegashima LA-Y2 Kestrel-7: ESA, pad TBD Tern-5: unknown provider, Sriharikota SLP
Every launch has a name, so read it with brackets; use get() with a default for the provider and the pad.
Hints
Creating Dictionaries
# A dictionary stores pairs: a key, then its value
webb = {
"name": "James Webb Space Telescope",
"mirror_metres": 6.5,
"launched": 2021,
"instruments": 4,
"infrared": True,
}
print(webb)
# Square brackets look up a value by its key
print("Mirror width:", webb["mirror_metres"], "metres")
# get() returns a fallback instead of crashing on a missing key
print("Cost:", webb.get("cost", "not recorded"))
# The dict() function builds the same thing from keyword arguments
hubble = dict(name="Hubble", mirror_metres=2.4, launched=1990)
print("Hubble mirror:", hubble["mirror_metres"], "metres")
# Keys do not have to be text. Anything unchangeable works
launch_log = {
1990: "Hubble",
2021: "Webb",
(2027, "planned"): "Roman",
}
print(launch_log[1990])
print("Missions logged:", len(launch_log))
print("Anything launched in 2021?", 2021 in launch_log)
Separate arguments with commas. They're passed on every Run as sys.argv[1:].