MediumPro challengePython

Strategy

PythonDesign PatternsBehavioral

Strategy lets you swap an algorithm at runtime by injecting an object
that implements a common interface, instead of branching inside the caller.

Implement PercentageDiscount (percent) and FlatDiscount
(amount_cents), both applying to a cart total in integer cents
(never floats — the classic reason real payment code avoids float money).
NoDiscount is already done for you.

solve(orders) checks out each order dict {'total_cents':..., 'strategy': {...}}
through the matching strategy and returns the final totals.

Sample tests

Test #1No discount
Input: [[{"strategy":{"kind":"none"},"total_cents":10000}]]
Output: [10000]
Test #210% off
Input: [[{"strategy":{"kind":"percentage","value":10},"total_cents":10000}]]
Output: [9000]
Test #3Flat discount
Input: [[{"strategy":{"kind":"flat","value":1500},"total_cents":5000}]]
Output: [3500]
Test #4Flat discount floors at zero
Input: [[{"strategy":{"kind":"flat","value":2500},"total_cents":1000}]]
Output: [0]