Start free

Novice · Formatting · 47 of 264

Receipt line

Read an item, its price and a quantity, and print a receipt line with the total price (two decimals).

Input: the item, the price (may have decimals) and the quantity, one per line. Output: <quantity> x <item> = <total>

Examples

Input
apple
0.5
3
Output
3 x apple = 1.50
Input
book
12.99
1
Output
1 x book = 12.99
Input
pen
1.2
10
Output
10 x pen = 12.00

One more test checks other inputs when you press Check.

Stuck? The idea behind formatting

An f-string puts values into text: f"{name} is {age}". Inside the braces, a format after a colon controls how the value looks.

:.2f gives two decimal places, :5 makes room for five characters, :>5 lines up to the right, :05 fills with zeros.

price = 3.5
print(f"Total: £{price:.2f}")
print(f"{7:03}")  # 007

Watch for: round() can drop a trailing zero (3.50 becomes 3.5); :.2f always shows two places.

All the formatting 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 formatting exercises