Bird
Raised Fist0

What will be printed by this code?

medium📝 Analysis Q5 of Q15
LLD - Design — Online Shopping Cart
What will be printed by this code?
price = 50
coupon = 60
final_price = max(price - coupon, 0)
print(final_price)
A-10
B0
C110
D50
Step-by-Step Solution
Solution:
  1. Step 1: Calculate price - coupon

    50 - 60 = -10.
  2. Step 2: Apply max function

    max(-10, 0) returns 0 to avoid negative price.
  3. Final Answer:

    0 -> Option B
  4. Quick Check:

    Price floor at zero = 0 [OK]
Quick Trick: Use max to prevent negative prices after discount [OK]
Common Mistakes:
MISTAKES
  • Allowing negative final price
  • Ignoring max function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes