Look Up a Price
FreeCreate <code>p</code>: the price of <code>"mouse"</code> from the <code>prices</code> dictionary.
Show the solution
p = prices["mouse"]
Right — dictionary[key] is Python's lookup, like a VLOOKUP on an exact match.
Practice by topic / Python & code / Python
Python is the most popular language for automating work: cleaning data, renaming files, crunching numbers. Each exercise runs your real code in the browser and checks it. These 5 exercises build up step by step, starting with look up a price, update stock, safe lookup.
3 of 5 free · no sign-up needed · instant feedback
Create <code>p</code>: the price of <code>"mouse"</code> from the <code>prices</code> dictionary.
p = prices["mouse"]
Right — dictionary[key] is Python's lookup, like a VLOOKUP on an exact match.
Five laptops were sold. Reduce <code>stock["laptop"]</code> by 5, and add a new item <code>"keyboard"</code> with 12 in stock.
stock["laptop"] -= 5, then stock["keyboard"] = 12
Good — the same square-bracket syntax both updates existing keys and adds new ones.
Create <code>rate</code>: the exchange rate for <code>currency</code> from <code>rates</code>, or <code>1.0</code> if the currency isn't in the dictionary.
rate = rates.get(currency, 1.0)
Exactly — .get(key, default) never crashes on a missing key, like IFERROR around a lookup.
Create <code>counts</code>: a dictionary of how many times each region appears in <code>orders</code> (e.g. <code>{"North": 3, ...}</code>).
Solution and instant grading: open it in the practice app (use one of your 20 free picks, or Pro).
Try it in the live editor →Each row in <code>rows</code> is <code>(rep, amount)</code>. Create <code>totals</code>: a dictionary of total sales per rep.
Solution and instant grading: open it in the practice app (use one of your 20 free picks, or Pro).
Try it in the live editor →