Bird
0
0

In the following code, what is the error that prevents correct discount application?

medium📝 Analysis Q14 of 15
LLD - Design — Online Shopping Cart
In the following code, what is the error that prevents correct discount application?
price = 200
discount = 20  # intended as 20%
final_price = price - discount
print(final_price)
APrice should be multiplied by discount directly
BDiscount should be converted to decimal before calculation
CDiscount should be added to price
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Identify discount representation

    Discount is 20 but intended as 20%, so it should be 0.2 in decimal.
  2. Step 2: Correct calculation method

    final_price should be price - (price * discount_decimal), not price - discount integer.
  3. Final Answer:

    Discount should be converted to decimal before calculation -> Option B
  4. Quick Check:

    20% = 0.2 decimal needed [OK]
Quick Trick: Convert percentage to decimal before subtracting [OK]
Common Mistakes:
  • Subtracting integer discount directly
  • Adding discount instead of subtracting
  • Ignoring percentage to decimal conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes