'Choosing two keys from a dictionary in python

I am trying to write a very simple code but am stuck. Here is my code:


print("WELCOME TO OUR JOINT")

name = input("What is your name? ")
print("Hello " + name + ",Welcome and Thank you for choosing Us. Here is our menu")

menu = ('Tea','Lemonade','Yogurt','Chapati','Mahamri','Samosa')
print(menu)

choice = input("What would you like today? \n")
order = choice.capitalize()
print(name + ", your order, "+ order + ", will be out in a moment. Enjoy your meal.\n")

price = {'Tea':10,'Lemonade':20,'Yogurt':100,'Chapati':10,'Mahamri':5,'Samosa':20}


for key in price.keys():
    if order == key:
        print(name, "your bill is Shs.",price[order])

Now, if you choose one object from the menu it works perfectly, I want it to be able to accept two or more from the menu and add up the bill. Kindly assist.



Solution 1:[1]

assuming your'e okay with splitting the items with "," here's how you could achieve that:

print("WELCOME TO OUR JOINT")

name = input("What is your name? ")
print("Hello " + name + ",Welcome and Thank you for choosing Us. Here is our menu")

menu = ('Tea','Lemonade','Yogurt','Chapati','Mahamri','Samosa')
print(menu)

choice = input("What would you like today? \n")

choice = choice.split(",")
order = [ch.capitalize() for ch in choice]
print(name + ", your order, "+ str(order) + ", will be out in a moment. Enjoy your meal.\n")

price = {'Tea':10,'Lemonade':20,'Yogurt':100,'Chapati':10,'Mahamri':5,'Samosa':20}

total_bill = 0
for key in order:
    if key in price:
        total_bill += price[key]

print(name, "your bill is Shs.", total_bill)

so the whole flow would look like this:

What is your name? gil
Hello gil,Welcome and Thank you for choosing Us. Here is our menu
('Tea', 'Lemonade', 'Yogurt', 'Chapati', 'Mahamri', 'Samosa')
What would you like today? 
tea,tea,yogurt
gil, your order, ['Tea', 'Tea', 'Yogurt'], will be out in a moment. Enjoy your meal.

gil your bill is Shs 120

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gil