Loyalty Discount Tier Calculator

Medium ⏱ 12 min 45% acceptance ★★★★☆ 4.2
Write a function 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%.

Examples

Example 1
Input
discount_percent(6, 40)
Output
20
Explanation

5+ years always gets 20%, regardless of order size.

Example 2
Input
discount_percent(3, 150)
Output
15
Explanation

2-4 years with an order of $100+ gets the boosted 15%.

Example 3
Input
discount_percent(1, 50)
Output
0
Explanation

Under 2 years and order below $100.

Constraints

  • years_member is a non-negative integer.
  • order_total is a non-negative number.

Topics

Conditional StatementsBusiness Logic

Companies

SwiggyZomatoFlipkart

Hints

Hint 1

Handle the 5+ year tier first since it does not depend on order_total.

Hint 2

Nest an order_total check inside the 2-4 year branch.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.