
Checkpoint
Checkpoint: The Cargo Manifest
The cargo ship Glimmer is about to sail. Before it leaves, the quartermaster needs a manifest: a list of what's on board and how heavy it all is.
Each piece of cargo is a tuple (item, kg). This checkpoint
uses the whole chapter: lists, append, looping over a list,
unpacking tuples and adding up totals.
Assignment
Use one for loop over manifest:
- Unpack each pair into
itemandkg. - Append every
itemtonames. - Add every
kgtototal. - If
kgis more than5, also append theitemtoheavy.
The prints are written for you. The output should be:
Items: rope, oil, map, gem
Total: 26 kg
Heavy: oil, gemUse one for loop over manifest:
- Unpack each pair into
itemandkg. - Append every
itemtonames. - Add every
kgtototal. - If
kgis more than5, also append theitemtoheavy.
The prints are written for you. The output should be:
Items: rope, oil, map, gem
Total: 26 kg
Heavy: oil, gemmain.py Python sleeping
Press Run to try your code, then Check to test it.