Refund Eligibility Engine

Medium ⏱ 12 min 51% acceptance ★★★★☆ 4.4
Write refund_amount(order) for a returns desk. order has price, days_since_delivery, opened (bool), category. Rules in priority order: electronics opened → 0; any item within 7 days → full price; 8-30 days → 50%; beyond 30 → 0. Return the refund value.

Examples

Example 1
Input
refund_amount({'price': 1000, 'days_since_delivery': 5, 'opened': True, 'category': 'clothing'})
Output
1000
Explanation

Within 7 days and not opened-electronics.

Example 2
Input
refund_amount({'price': 1000, 'days_since_delivery': 5, 'opened': True, 'category': 'electronics'})
Output
0
Explanation

The opened-electronics rule fires first.

Constraints

  • Rule order matters — encode it explicitly.
  • Return a number, not a string.

Topics

Business Logicpolicy rules

Companies

AmazonMyntraNykaa

Hints

Hint 1

Guard clauses in priority order read cleanest.

Hint 2

50% path: price * 0.5.

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