All problems
Price Elasticity
Problem
Compute demand after a price change under constant elasticity: demand0 * (price1 / price0)^elasticity.
Return 0.0 when price0 is not positive. A typical elasticity is negative, so raising price lowers demand.
Hint
Demand forecasting pipelines often include price as a causal driver.
Test cases
case 1
in: [100,10,11,-1.5]
expected: 86.67841720414474
case 2
in: [100,10,9,-1.5]
expected: 117.12139482105108
case 3
in: [50,0,5,-1]
expected: 0
case 4
in: [10,2,2,-2]
expected: 10
Starter codePython
def price_elasticity(demand0, price0, price1, elasticity):
# Your code here
pass4 test cases · run your code against them in the editor