930 B
930 B
type, title, xp, duration, difficulty
| type | title | xp | duration | difficulty |
|---|---|---|---|---|
| challenge | The Formatter | 50 | 25 | 2 |
The Formatter
[INCOMING — Mission Control, Earth]
Cadet, raw numbers like
9.99print fine, but29.970000000000002doesn't. Real programs format numbers. f-strings can do it inline:price = 9.99 f"${price:.2f}" # → "$9.99"The
:.2fis a format spec: two decimal places, fixed-point.Implement
format_receipt(price, qty)that returns a 3-line string:Item price: $<price> Quantity: <qty> Total: $<price * qty>Both prices use 2-decimal formatting. Use
\nto join lines.[END TRANSMISSION]
Your Task
Open starter/starter.py. Compute total, then return a single
f-string with \n separators.
Objectives
format_receipt(9.99, 3)returns the exact 3-line string- Prices format to 2 decimal places
- Works for any positive
priceandqty