seed: curriculum content
This commit is contained in:
44
1.solar-system/2.first-light/08.the-formatter/index.md
Normal file
44
1.solar-system/2.first-light/08.the-formatter/index.md
Normal file
@@ -0,0 +1,44 @@
|
||||
---
|
||||
type: challenge
|
||||
title: "The Formatter"
|
||||
xp: 50
|
||||
duration: 25
|
||||
difficulty: 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:
|
||||
>
|
||||
> ```python
|
||||
> 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`
|
||||
Reference in New Issue
Block a user