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

# Restaurant Class
class Restaurant():
    def __init__(self, restaurant):
        self.restaurant = restaurant

    def getallrestaurant(self):
        return self.restaurant

# Ingredients 
class Ingredient():
    def __init__(self, ingredients):
        self.ingredients = ingredients

# Dish Class       
class Dish():
    def __init__(self, dishes):
        self.dishes = dishes

    def getalldishes(self):
        return self.dishes


if __name__ == '__main__':

    restaurant = [{
        'id': 1,
        'name':'\nAli Resturant',
        'dishes':[1,2,3,4,5]
        }]
        
    ingredients = [
        {
            'id' : 1,
            'name' : 'Pizza'
        },
        {
            'id' : 2,
            'name' : 'Burger'
        },
        {
            'id' : 3,
            'name' : 'Fries'
        },
        {
            'id' : 4,
            'name' : 'Drink'
        },
        {
            'id' : 5,
            'name' : 'Noodle'
        }
    ]

    dishes = [
        {
            'id' : 1,
            'name' : 'Pizza',
            'ingredients' : [1],
            'price' : 1500
        },
        {
            'id' : 2,
            'name' : 'Burger',
            'ingredients' : [2],
            'price' : 350
        },
        {
            'id' : 3,
            'name' : 'Fries',
            'ingredients' : [3],
            'price' : 150
        },
        {
            'id' : 4,
            'name' : 'Drink',
            'ingredients' : [4],
            'price' : 100
        },
        {
            'id' : 5,
            'name' : 'Noodle',
            'ingredients' : [5],
            'price' : 250
        }
    ]

restaurant_obj = Restaurant(restaurant)
ingrediants_obj = Ingredient(ingredients)
dish_obj = Dish(dishes)




 # start while loop and start taking orders


# Restaurant Name Get
getrestaurant = restaurant_obj.getallrestaurant()

for rest_name in getrestaurant:
    print(rest_name['name'])

print ("\n==========Menu============\n")

# Dishes Name Get
getdishes = dish_obj.getalldishes()

for dish in getdishes:
    print(dish['name'])

while (True):
    order = input("\nEnter your Order =  " )

    if order == 'E':
        break

    # find Same Name in Dishes class
    find = [item for item in getdishes if item.get('name')== order]
    
    #Sum and Calculate the Order and give Billing
    if len(find):
        sum = sum + find[0]['price']
        print ("\nAdd More Dishes OR Press E for Bill! ")
    else:
        print("\nEnter Right Item\n")
    
print("\nThanks For Order\nYour total bill is = " ,sum)


What I have tried:

Are there be any improvements with this code?
Posted
Updated 17-May-21 4:38am
v2
Comments
Richard MacCutchan 17-May-21 10:10am    
Probably yes, but you need to format it properly first. Please edit the post and add the <pre lang="Python"> and </pre> tags around it, so it is properly readable.
CHill60 17-May-21 10:18am    
Depends what you mean by "improvement"

1 solution

Well ... depends what you mean by "improvement":
1) Readability
2) Maintenance
3) Speed
4) Memory usage
5) User Interface
6) Enhancements

They are all "improvements" of one form or another, and it's not possible to be specific without knowing the criteria on which the app would be judged.

I would say that the commenting is ... very poor - you are documenting what teh code does instead of why it does it, or even inaccurate:
Python
#Sum and Calculate the Order and give Billing
if len(find):
    sum = sum + find[0]['price']
    print ("\nAdd More Dishes OR Press E for Bill! ")
else:
    print("\nEnter Right Item\n")

The variable names are poor: "getdishes" for example.
From a user point of view it's pretty nasty - would you want to use it for real, all day, every day?

But as I said: we have no idea what the context of this is - other than "it's your homework" so "improving" it is beyond our bailiwick.
 
Share this answer
 

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