âBallpark ordersâ challenge troubles
Hi all, Iâm trying to complete the Code Coach challenge âBallpark Ordersâ using Python. I want the code to take an input string of several words (food orders), compare those to a dictionary, and add up the total price of each item that was ordered. This results in 5, so I assume something is wrong with my if statement; I donât think it is checking the words in the string in the way that I want it to. Any help? 1 prices = { 2 "nachos": 6.0, 3 "pizza": 6.0, 4 "cheeseburger": 10.0, 5 "water": 4.0, 6 "coke": 5.0 7 } 8 9 order = input() #example: âwater water coke pizzaâ 10 order = (x for x in order) 11 12 def place_order(dict, key): 13 total = 0 14 if key in dict: 15 total += dict.get(key) 16 return total 17 else: 18 total += 5.0 19 return total 20 21 result = place_order(prices, order) 22 23 print(result) EDIT I got as far as making the order into separate strings with this: order = "pizza pizza water coke" order = order.split() total= 0 if order in prices: total += prices.get(order) print(total) else: total += 5.0 print(total) Now the error I receive is that lists are unhashable. Hmm!