The crew used two bottles of water at lunch. Then the supply ship dropped off more tape, and now there are seven rolls. "Let's update the inventory!" Rocket says.
He starts typing a whole new dictionary from the top. Raven stops him. "What do you notice? Only two numbers changed. The oats are the same."
Nova taps one glowing jar with her wing. "Would you like a hint? You can change just one value if you know its key."
Put the dictionary name and the key on the left of =. Put the new value on the right.
You can use the old value too, just like fuel = fuel + 15.
inventory = {"water": 12, "oats": 8, "tape": 3}
inventory["water"] = inventory["water"] - 2
inventory["tape"] = 7
print(inventory["water"])
print(inventory["tape"])
print(inventory["oats"]) | The screen shows |
|---|
| 10 |
| 7 |
| 8 |
| Line | water | oats | tape |
|---|---|---|---|
| 1 | 12 | 8 | 3 |
| 2 | 10 | 8 | 3 |
| 3 | 10 | 8 | 7 |
fuel = {"shuttle": 40, "rover": 15}
fuel["shuttle"] = fuel["shuttle"] + 25
fuel["rover"] = fuel["rover"] * 2
print(fuel) scores = {"Rocket": 5, "Raven": 5}
scores["Rocket"] = scores["Rocket"] + 3
scores["Raven"] = scores["Rocket"]
print(scores["Raven"]) air = {"deck1": 90, "deck2": 75}
air["deck1"] = air["deck1"] - 10
air["deck2"] = air["deck2"] + 5
air["deck1"] = air["deck1"] - 10
print(air) | Statement | True or false? |
|---|---|
| inventory["oats"] = 9 changes the oats value. | ? |
| You must retype the whole dictionary to change one value. | ? |
| The right side of = is worked out first. | ? |
| After d["a"] = 1 and then d["a"] = 2, d["a"] is 1. | ? |
Nice updating! Tomorrow you will add brand new keys.