Print one receipt line: the item name left-aligned in 10 characters, the quantity right-aligned in 4, and the total price right-aligned in 10 with two decimals.
What to build
One neatly formatted line of a receipt.
Requirements
- Left-align the name in 10 characters.
- Right-align the quantity in 4 characters.
- Right-align the total price in 10 characters, with two decimals.
Input
Three lines: the item name (at most 10 characters), the quantity (a whole number), and the unit price.
Output
One formatted line, for example Rice 2 137.00.
Constraints
The name has at most 10 characters. The total price is the quantity times the unit price.
Example
Input:
Rice
2
68.5
Output:
Rice 2 137.00
Why it works
Because every field has a fixed width, lines printed this way form straight columns, whatever the values are.
Examples
Rice 2 68.5
Rice 2 137.00
Pen 10 5
Pen 10 50.00
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
f"{name:<10}" left-aligns in 10 characters.
Hint 2
f"{total:>10.2f}" right-aligns in 10 with two decimals.
Solution
Show one correct solution (try it yourself first)
name = input()
qty = int(input())
price = float(input())
print(f"{name:<10}{qty:>4}{qty * price:>10.2f}")