Deviopath › Python

Format a Price

Easy · Strings

An f-string puts values inside text: f"Total: {x}". After a colon you can add a format spec. {x:.2f} shows a number with exactly 2 decimal places, rounding if needed.

Write a function format_price(amount) that returns the amount as a price string with a dollar sign and 2 decimals, like "$4.50".

Next: Mask a Card Number