Challenge 1
Read an optional theme setting and use "light" only when APP_THEME is absent.
import os
# The launcher can supply APP_THEME.
theme =
print(theme)
Press Ctrl⌘Enter to check your answer
Practise optional lookups, required settings, numeric validation, and explicit Boolean parsing.
Challenge 1
import os
# The launcher can supply APP_THEME.
theme =
print(theme)
Press Ctrl⌘Enter to check your answer
Challenge 2
def required_setting(environ, name):
value =
if value is None or not value.strip():
raise ValueError(f"{name} must be set")
return value.strip()
print(required_setting({"APP_REGION": " eu-west "}, "APP_REGION"))
Press Ctrl⌘Enter to check your answer
Challenge 3
environ = {"APP_PORT": "8080"}
raw = environ.get("APP_PORT", "8000")
port =
if not 1 <= port <= 65535:
raise ValueError("APP_PORT is outside the allowed range")
print(port)
Press Ctrl⌘Enter to check your answer
Challenge 4
def read_flag(environ, name, default=False):
raw = environ.get(name)
if raw is None:
return default
normalized = raw.strip().casefold()
print(read_flag({"APP_DEBUG": "yes"}, "APP_DEBUG"))
print(read_flag({"APP_DEBUG": "off"}, "APP_DEBUG"))
Press Ctrl⌘Enter to check your answer