discount_percent(years_member, order_total) for a loyalty program. Members of 5+ years get 20% off. Members of 2-4 years get 10% off, but only 15% off if the order is also at least $100. Members under 2 years get 5% off on orders of $100 or more, otherwise 0%.discount_percent(6, 40)
20
5+ years always gets 20%, regardless of order size.
discount_percent(3, 150)
15
2-4 years with an order of $100+ gets the boosted 15%.
discount_percent(1, 50)
0
Under 2 years and order below $100.
Handle the 5+ year tier first since it does not depend on order_total.
Nest an order_total check inside the 2-4 year branch.