Skip to content

Commit cf7ed38

Browse files
committed
hints
1 parent 2d4fa45 commit cf7ed38

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

core/chapters/c12_dictionaries.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -931,14 +931,23 @@ def total_cost_per_item(quantities, prices):
931931
)
932932
"""
933933
hints = """
934-
You need to iterate through the items in the `quantities` dictionary.
935-
For each `item`, calculate the total cost for that item (quantity * price).
936-
Store this calculated cost in the `totals` dictionary.
937-
The key for the `totals` dictionary should be the `item` name.
938-
Use the dictionary assignment syntax: `totals[item] = calculated_cost`.
939-
Make sure this assignment happens *inside* the loop.
940-
The function should return the `totals` dictionary after the loop finishes.
941-
"""
934+
You only need to fill in the `___` part.
935+
But if you want, you could also just put a variable name there, and then add a new line below it.
936+
Look at the tests with `assert_equal`. In the first example, the expected output is `{'apple': 6}`. Why?
937+
Because the customer bought 2 apples, and each apple costs 3, so the total cost is `2 * 3 = 6`.
938+
The `'box': 5` part is ignored because the customer didn't buy any boxes. It just means that the price of a box is 5.
939+
You need to add a new key-value pair to a dictionary.
940+
Identify the dictionary, the key, and the value.
941+
They are all present in the given code already.
942+
The value is the total cost for that item, which is the quantity multiplied by the price.
943+
i.e. `quantities[item] * prices[item]`.
944+
The dictionary is the thing that this function creates, builds, and returns.
945+
i.e. `totals`.
946+
Note how `'apple'` is a key in all three dictionaries in that test.
947+
i.e. the dictionaries `quantities`, `prices`, and `totals`.
948+
"""
949+
950+
requirements = "Run the program above, but replace the `___` with the correct code."
942951

943952
def solution(self):
944953
def total_cost_per_item(quantities: Dict[str, int], prices: Dict[str, int]):

0 commit comments

Comments
 (0)