← Back to challenges

Profit Margin

PythonHardmathformattingnumbersstrings

Instructions

Create a function that calculates the profit margin given cost_price and sales_price. Return the result as a percentage formatted string, and rounded to one decimal. To calculate profit margin you subtract the cost from the sales price, then divide by sales price.

Examples

profit_margin(50, 50) ➞ "0.0%"

profit_margin(28, 39) ➞ "28.2%"

profit_margin(33, 84) ➞ "60.7%"

Notes

  • Remember to return the result as a percentage formatted string.
  • Only one decimal should be included.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: The Museum of Incredibly DULL Things