116. Python Program to Build a Price List from Input
MediumChange items
Overview
Build a dictionary step by step, one pair per round of a loop.
Problem Statement
The first line says how many items follow (1 or more). Then, for each item, read its name on one line and its price (a whole number) on the next. Store them in a dictionary, item as key and price as value. If an item comes twice, the later price replaces the earlier one. Print the dictionary, then Different items: and the number of pairs. For example, for 3, then tea 15, coffee 25 and juice 40:
{'tea': 15, 'coffee': 25, 'juice': 40}
Different items: 3
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
One value per line, in this order. Example:
3
tea
15
coffee
25
juice
40
Output
The output for that example:
{'tea': 15, 'coffee': 25, 'juice': 40}
Different items: 3
The tests try 3 different inputs.