MediumPro challengePython

Decorator

PythonDesign PatternsStructural

Decorator wraps an object to add behavior, without subclassing every
possible combination of features.

Coffee costs 200 (cents) and describes itself as 'Coffee'.
Implement MilkDecorator (+50 cents, ' + Milk') and SugarDecorator
(+20 cents, ' + Sugar') — each wraps another Coffee-shaped object and
adds to its cost/description.

solve(orders) wraps a fresh Coffee with the addons listed for each
order (in order) and returns {'description':..., 'cost_cents':...}.

Costs are in integer cents, not float dollars — the same reason real
payment systems never use floats for money.

Sample tests

Test #1No addons
Input: [[[]]]
Output: [{"cost_cents":200,"description":"Coffee"}]
Test #2One addon
Input: [[["milk"]]]
Output: [{"cost_cents":250,"description":"Coffee + Milk"}]
Test #3Two stacked addons
Input: [[["milk","sugar"]]]
Output: [{"cost_cents":270,"description":"Coffee + Milk + Sugar"}]