-1
menuePrice = { 
"margherita":5.00,#the price is 5.00
"pepperoni": 7.50,
"ham and pinaple": 1,
"vegan pizza": 1,
"americano": 1,
"meat pizza": 1,
"gluten free pizza": 1,
"dary free pizza": 1,
"pizza free pizza": 1,
"p": 1,
}

And this is the list pizzaOrder = ["margherita", "pepperoni"]#this is what the customer has ordered

Hi, I would like to get the values of whatever is in pizzaOrder from menuePrice, add the values together and print them out as a final price. Eg: Total: £12.5. I havent tried anyhting as i have no clue how to go about doing this and i am struggling to formulate my question into words for google. This is for a pizza order chat bot if that helps. Sorry if the answer is easy, i/m quite new to dictionarys in python/

azro
  • 53,056
  • 7
  • 34
  • 70
Oran
  • 45
  • 5

2 Answers2

0

Let's say you want to get the total price:

menuePrice = { 
    "margherita":5.00,#the price is 5.00
    "pepperoni": 7.50,
    "ham and pinaple": 1,
    "vegan pizza": 1,
    "americano": 1,
    "meat pizza": 1,
    "gluten free pizza": 1,
    "dary free pizza": 1,
    "pizza free pizza": 1,
    "p": 1,
}

pizzaOrder = ["margherita", "pepperoni"]  #this is what the customer has ordered
total = 0

for pizza in pizzaOrder:
    total += menuePrice[pizza]

print(total)
Alexandre Senges
  • 1,474
  • 1
  • 13
  • 22
0

Just iterate (that's the word) over the dictionary's values using a for-each loop:

total = 0
for price in menuePrice.values():
    total += price
Guy_g23
  • 316
  • 2
  • 7