Bird
0
0

Given the code:

medium📝 Analysis Q4 of 15
LLD - Design — Online Shopping Cart
Given the code:
price = 200
coupon_discount = 30
final_price = price - coupon_discount if price > coupon_discount else 0
print(final_price)

What is the output?
AError
B0
C170
D230
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition price > coupon_discount

    200 > 30 is True, so apply price - coupon_discount.
  2. Step 2: Calculate final_price

    200 - 30 = 170, so final_price is 170.
  3. Final Answer:

    170 -> Option C
  4. Quick Check:

    Conditional discount applied = 170 [OK]
Quick Trick: Check conditions before subtracting discounts [OK]
Common Mistakes:
  • Ignoring condition and subtracting anyway
  • Confusing else output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes