CJCoding With Joseph
15free / daySign inCreate account

Totals By Category

Keep a running total per category. Input: the first line is a whole number n, followed by n pairs of lines, a category name and then an amount as a decimal number; read them with a bare input(), no prompts, using range(n). Use a dict of running sums: use in to check whether the category is already a key, adding the amount to its total if so and otherwise storing the amount as the first total. After the last pair, print one line per category in the order first seen, in the form <category>: <total> with the total to two decimals.

Expected Output:

food: 19.75
fuel: 40.00
rent: 800.00

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Dictionaries
📥 Auto-Input:
4\nfood\n12.5\nfuel\n40\nfood\n7.25\nrent\n800\n
This input is automatically fed to your program's stdin
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.