Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Python
total_calories = 0

class Dish(object):
    def __init__(self, name, ingredients, calories):
        self.name = name
        self.ingredients = ingredients
        self.calories = calories
    
    def getname(self):
        return self.name
    
    def getingredients(self):
        return self.ingredients
    
    def getcalories(self):
        return self.calories
    
class Pasta(Dish):
    def __init__(self):
        Dish.__init__(self, "Pasta", "Macroni, Chicken, Salt, Vinegar, Soy sauce, Chilli sauce", 131)
        
    def getinfo(self):
        print(self.name, "\nIngredients:", self.ingredients, "\nCalories:", self.calories, "\n")
        
class Pizza(Dish):
    def __init__(self):
        Dish.__init__(self, "Pizza", "Chicken, Dough, Tomato Sauce, Cheese, Vegetables", 266)
        
    def getinfo(self):
        Pasta.getinfo(self)
        
class Burger(Dish):
    def __init__(self):
        Dish.__init__(self, "Burger", "Bun, Beef, Cheese, Lettuce, Ketchup", 225)
        
    def getinfo(self):
        Pasta.getinfo(self)
        
        
class Shawarma(Dish):
    def __init__(self):
        Dish.__init__(self, "Shawarma", "Pitta Bread, Ground Meat, Ketchup, Mayonnaise, Spices", 300)
    def getinfo(self):
        Pasta.getinfo(self)
        
p = Pasta()
i = Pizza()
b = Burger()
s = Shawarma()

p.getinfo()
i.getinfo()
b.getinfo()
s.getinfo()

quantity = int(input("How much food would you like to oder:"))

for i in range(1, quantity):
    d = input("enter the dish you want to order:")
    
    while (d != "Pasta" or "pasta" or "Pizza" or "pizza" or "Burger" or "burger" or "Shawarma" or "shawarma"):
        print("Try again from the menu")
        d = input("enter the dish you want to order:")
        
    if (d == "Pasta" or "pasta"):
        total_calories = total_calories + 131
        
    elif (d == "Pizza" or "pizza"):
        total_calories = total_calories + 266
        
    elif (d == "Burger" or "burger"):
        total_calories = total_calories + 225
        
    else:
        total_calories = total_calories + 300
        
print("Calories Consumed:", total_calories)


What I have tried:

I can't get out of the while loop after getting a re-input from the user if he does not enter from the menu
Posted
Updated 7-Jun-21 5:26am
v2

or doesn't work like that.
Try like this:
Python
d = input("enter the dish you want to order:")

while (d != "Pasta" and d != "pasta" 
   and d != "Pizza" and d != "pizza" 
   and d != "Burger" and d != "burger"
   and d != "Shawarma" and d!= "shawarma"):
    print("Try again from the menu")
    d = input("enter the dish you want to order:")
 
Share this answer
 
Python
while (d != "Pasta" or "pasta" or "Pizza" or "pizza" or "Burger" or "burger" or "Shawarma" or "shawarma"):

That statement will never fail because each expression after or is a non-zero value so will always be true. You must use complete expressions in every case. You also need to use and rather than or so all conditions are tested.
Python
while (d != "Pasta" and d != "pasta" and d != "Pizza" and d != "pizza" and d != "Burger" and d != "burger" and d != "Shawarma" and d != "shawarma"):

You may also like to use a counter so the user cannot enter thousands of invalid words.

[edit]
A better test would be to use the lower method so you only need four tests:
Python
while (d.lower() != "pasta" and d.lower() != "pizza" and d.lower() != "burger" and d.lower() != "shawarma"):


[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900