Files
curriculum/1.solar-system/2.first-light/08.the-formatter/index.md

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.99 print fine, but 29.970000000000002 doesn't. Real programs format numbers. f-strings can do it inline:

price = 9.99
f"${price:.2f}"   # → "$9.99"

The :.2f is 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 \n to 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 price and qty