Start free

Beginner · Lists · 106 of 264

Shopping total

Read a shopping list and print the total price with two decimals.

Input: n, then n lines each with an item and its price, separated by a space. Output: Total: <sum>

Examples

Input
3
bread 1.20
milk 0.99
cheese 3.50
Output
Total: 5.69
Input
1
apple 0.30
Output
Total: 0.30

One more test checks other inputs when you press Check.

Stuck? The idea behind lists

A list keeps several values in order: [3, 9, 1]. Its items are numbered from 0, like a string's characters.

append() adds to the end; sum(), min(), max(), len() and sorted() work on a whole list. Read numbers from one line with input().split() and int().

numbers = [int(x) for x in input().split()]
print(sum(numbers), max(numbers))
numbers.append(0)
print(numbers)

Watch for: split() gives text: "10" sorts before "9". Turn each item into a number before comparing or adding.

All the lists exercises
Your code
Opening the code editor…
Python 3.14 in your browser
Output
Run shows what your program prints. Check tests it on every example and the hidden tests.

More lists exercises