Bird
Raised Fist0

Which syntax correctly applies a 10% discount to a price variable in Python?

easy🧠 Conceptual Q3 of Q15
LLD - Design — Online Shopping Cart
Which syntax correctly applies a 10% discount to a price variable in Python?
Adiscounted_price = price - 10
Bdiscounted_price = price + 0.1
Cdiscounted_price = price / 10
Ddiscounted_price = price * 0.9
Step-by-Step Solution
Solution:
  1. Step 1: Understand percentage discount calculation

    A 10% discount means paying 90% of the price, so multiply by 0.9.
  2. Step 2: Check each option

    Only multiplying price by 0.9 correctly applies 10% off.
  3. Final Answer:

    discounted_price = price * 0.9 -> Option D
  4. Quick Check:

    10% off = multiply by 0.9 [OK]
Quick Trick: Multiply price by (1 - discount%) to apply discount [OK]
Common Mistakes:
MISTAKES
  • Adding discount instead of subtracting
  • Dividing price incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes