Build week begins! Rocket cracks his knuckles. "I will type the whole tracker before lunch!"
Raven holds up the plan from last week. "What do you notice about the plan?"
"It is in parts," Rocket says. "And there is a test for each part." He takes a breath. "One part at a time."
"I will be navigator, you be driver," Raven says.
Nova hovers between them. "Here is a hint. Every helper needs data to work on. Start there."
The supplies go in a dictionary. The command tree from week 10 goes in nested dictionaries.
# Part 1: the data
inventory = {
"water": 40,
"seeds": 12,
"lamps": 3,
"maps": 7,
"rope": 2,
"tools": 15,
}
fleet = {
"name": "Ada",
"crew": [
{"name": "Bo", "crew": [
{"name": "Cy", "crew": []},
{"name": "Dee", "crew": []},
]},
{"name": "Eve", "crew": [
{"name": "Fen", "crew": []},
{"name": "Gil", "crew": []},
{"name": "Hal", "crew": []},
]},
],
}
# Part 2: count everything
def total_items(stock):
total = ____
for item in stock:
total = total + ____
return total
def total_items(stock):
total = 0
for item in stock:
total = total + stock[item]
return total
print(total_items({"water": 40, "seeds": 12}))
print(total_items({})) def total_items(stock):
total = 0
for item in stock:
total = total + stock[item]
return total
print(total_items({"rope": 2, "maps": 7}))
print(total_items({"tools": 15})) | Statement | True or false? |
|---|---|
| inventory has a key for rope. | ? |
| total_items returns the number of keys. | ? |
| Eve has three crew in the fleet tree. | ? |
| The driver types and the navigator checks. | ? |
Two parts done! Data plus a tested helper is a strong start. Tomorrow we find what is running low.