Codington
0 of 6 problems solved • 0%

Exercise prompt

Look Up Stock

Looking up a missing dictionary key with brackets raises an error. The get method accepts a fallback as its second argument.

Example

A departures board shows a gate even when a flight has not been assigned one.

gates = {"SK10": "C4"} print(gates.get("SK10", "Pending")) # C4 print(gates.get("SK88", "Pending")) # Pending print("SK88" in gates) # False

The fallback supplies a value for the display while the stored gates stay the same. A quantity lookup needs a numeric fallback.

Your task

Complete stock_for(stock, item) to return the saved quantity, or 0 for an unknown item. Do not insert missing items into stock.

stock_for({"pens": 4}, "pens") # 4 stock_for({"pens": 4}, "clips") # 0