I am working on a project with a goal to create a program that asks the users what ingredients they would like in their sandwich. In order to ask the users what type of bread or milk or other ingredients they would like, I am using inputMenu() function from pyinputplus such that a user will select choices from the list of menus, then prices for the user’s choices will be drawn from a dictionary of prices into an empty list, where I will then compute the total price for the Sandwich.
This is my program so far:
import pyinputplus as pyip
prices = {
'teaType': {'coffee': 7, 'lipton': 5.5, 'toptea': 5, 'bournvita': 6, 'milo': 6.5},
'milkType': {'peak': 11, 'three_crowns': 9.2, 'cowbell':8.7, 'coolcow': 8},
'breadType': {'wheat_bread': 22, 'white_bread': 15, 'coconut_bread': 17, 'sourdough': 20, 'buttered_bread': 18},
'proteinType':{'chicken': 12, 'turkey': 10.5, 'beef': 9.3, 'ham': 13, 'tofu': 8.7},
'cheeseType': {'swiss': 4, 'shawarma': 5, 'mozerrella': 4.3, 'cheddar':3.8},
'butterType': {'mayo': 2.6, 'mustard': 2.4, 'lettuce': 3, 'tomato': 5}
}
selectedMenu = []
tea = pyip.inputMenu(['coffee', 'lipton', 'toptea', 'bournvita', 'milo'],
prompt='Type a number for the tea you want.\n', numbered=True)
if tea in prices['teaType'].keys():
selectedMenu.append(prices['teaType'].values())
milk = pyip.inputMenu(['peak', 'three_crowns', 'cowbell', 'coolcow'],
prompt='Select the milk you want with it\n', numbered=True)
if milk in prices['milkType'].keys():
selectedMenu.append(prices['milkType'].values())
print(selectedMenu)
The challenge is that when I print the selectMenu list, I got the entire list of prices in the dictionary as follows: [dict_values([7, 5.5, 5, 6, 6.5]), dict_values([11, 9.2, 8.7, 8])].
What I want to achieve is to go into the dictionary of prices and pick only the prices for the items that the user has picked into the selectMenu list and then sum up the total price for the user.
I don’t how or what other ways to achieve it. I need help with it.