Space Python Loading Python…

Modifying Dictionaries

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Mass by category

Write the codeMedium 2 stages

Add up the cargo mass of each category into a dict with totals[category] = totals.get(category, 0) + mass, then list the categories from heaviest to lightest with their share of the load.

Start the challenge

Settings with defaults

Write the codeMedium 2 stages

Build a user's settings by copying the defaults and laying their own values on top with update(), so any setting they haven't changed falls back, then warn about unknown keys instead of saving them.

Start the challenge

Config loader

Write the codeHard 3 stages

Load the downlink module's JSON settings over a copy of the defaults, check each value's type and range and report every problem in one go, then wrap it all in a load_config() that never crashes, even on broken JSON.

Start the challenge

Discussion

Stuck on this example or want to go further? Ask here, or see what others asked.

Log in to ask and reply.

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:].