Drill

ProblemsPython › finance

Profit margin in permille

mediumfinancePython

A store wants its margin as a whole per-mille number: how much of each minor unit of revenue survives as profit.

profit_margin(revenue: int, cost: int) → int

Solve it in the editor →

Where you start

def profit_margin(revenue: int, cost: int) -> int:
    

Worked examples

CallResult
profit_margin(1000, 600)400
profit_margin(1000, 1000)0
profit_margin(1000, 1200)-200
profit_margin(0, 100)0

Hint

Subtract the cost from revenue, scale by 1000, divide by revenue.

Reference solution in Python
def profit_margin(revenue: int, cost: int) -> int:
    if revenue <= 0:
        return 0
    return (revenue - cost) * 1000 // revenue

The same problem in another language

More finance problems in Python