Combined Operators: Discount Calculator

Medium ⏱ 12 min 51% acceptance ★★★★★ 4.8
Write a function final_price(price, is_member, coupon_percent) that computes a final checkout price. Members always get an extra flat 5% off on top of the coupon discount. Apply the coupon percentage first (price * (1 - coupon_percent / 100)), then apply the membership discount if is_member is True (multiply by 0.95). Round the final result to 2 decimal places. Combine arithmetic, comparison, and logical operators as needed.

Examples

Example 1
Input
final_price(200, True, 10)
Output
171.0
Explanation

200 * 0.90 = 180, then 180 * 0.95 = 171.0 for members.

Example 2
Input
final_price(200, False, 10)
Output
180.0
Explanation

No membership discount applied.

Constraints

  • price > 0; coupon_percent is between 0 and 100; is_member is a bool.

Topics

Operatorsmixed operatorsBusiness Logic

Companies

FlipkartWalmartAmazon

Hints

Hint 1

Apply the coupon first: `price * (1 - coupon_percent / 100)`.

Hint 2

Then conditionally multiply by 0.95 using an if or a ternary, and round(..., 2) at the end.

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