Bird
Raised Fist0

Given the following code snippet, what will be the total price of the order?

medium📝 Analysis Q4 of Q15
LLD - Design — Food Delivery System
Given the following code snippet, what will be the total price of the order?
menu = Menu()
menu.add_item('Burger', 5.0)
menu.add_item('Fries', 2.0)
order = Order()
order.add_item('Burger', 2)
order.add_item('Fries', 3)
total = order.calculate_total(menu)
A16.0
B11.0
C19.0
D21.0
Step-by-Step Solution
Solution:
  1. Step 1: Calculate cost for each item

    Burger price is 5.0, quantity 2 -> 5.0 * 2 = 10.0; Fries price is 2.0, quantity 3 -> 2.0 * 3 = 6.0
  2. Step 2: Sum the costs

    Total = 10.0 + 6.0 = 16.0
  3. Final Answer:

    16.0 -> Option A
  4. Quick Check:

    Total price = sum of (price * quantity) [OK]
Quick Trick: Multiply price by quantity, then sum all items [OK]
Common Mistakes:
MISTAKES
  • Adding quantities instead of prices
  • Ignoring quantity
  • Using wrong prices

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes