Market basket total
A weekend market records three item lines. Each line contains a decimal unit price followed by an integer quantity. Calculate the complete basket value and print it with exactly two digits after the decimal point.
Input
Three lines, each containing a price and quantity separated by one space.
Output
One line: the basket total formatted to two decimal places.
Example 1
Input
2.50 2 1.25 3 4.00 1
Output
12.75
5.00 + 3.75 + 4.00 gives 12.75.
Constraints
- 0.01 <= price <= 1000
- 1 <= quantity <= 100
Hints
Hint 1 of 3
Split each line into two strings.
Hint 2 of 3
Convert the price with float and quantity with int.
Hint 3 of 3
Add price * quantity inside the loop, then use :.2f when printing.
Solution
Show a reference solution and explanation
total = 0.0
for _ in range(3):
price, quantity = input().split()
total += float(price) * int(quantity)
print(f"{total:.2f}")
Why it works
The loop handles every item line in the same way. Converting the two fields to their numeric types makes multiplication meaningful, while the format specifier controls how the final value is displayed.
Lesson for this exercise: Operators in Python