← Back to Dictionaries
Question 303
Order Total From A Menu
Order Total From A Menu
Price a whole order against a menu you declare yourself as the dict {'coffee': 2.5, 'bagel': 1.75, 'soup': 4.0}. Input: the first line is a whole number n, then n pairs of lines, an item name and then a quantity as a whole number; read them with a bare input(), no prompts, using range(n). For each pair use in to check the key first: an item on the menu adds its price times the quantity to a running total, while an unknown item prints Unknown item: <name> immediately and adds nothing. After the last pair print Total: <value> with two decimals. Output: one line per unknown item, in input order, then the total line.
Expected Output:
Unknown item: cake Total: 9.00
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Dictionaries
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.