0% found this document useful (0 votes)
27 views5 pages

Project 2

The document defines classes for food items, orders, menus and user management. It allows users to register, login, view menus to place orders and see order history. The main function runs a loop to handle user interactions.

Uploaded by

VIKAS SHARMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views5 pages

Project 2

The document defines classes for food items, orders, menus and user management. It allows users to register, login, view menus to place orders and see order history. The main function runs a loop to handle user interactions.

Uploaded by

VIKAS SHARMA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

import random

class FoodItem:

def __init__(self, id, name, cuisine, price):

self.id = id

self.name = name

self.cuisine = cuisine

self.price = price

class Order:

def __init__(self, user):

self.order_id = random.randint(1000, 9999)

self.user = user

self.items = []

def add_item(self, item, quantity=1):

self.items.append({"item": item, "quantity": quantity})

def calculate_total(self):

return sum(item["item"].price * item["quantity"] for item in self.items)

class Menu:

def __init__(self):

self.items = [

FoodItem(1, "Paneer Tikka", "Indian", 150.0),

FoodItem(2, "Chicken Biryani", "Indian", 250.0),

FoodItem(3, "Sushi", "Japanese", 300.0),

FoodItem(4, "Margherita Pizza", "Italian", 200.0),

FoodItem(5, "Pad Thai", "Thai", 180.0),


FoodItem(6, "Samosa", "Indian", 20.0),

FoodItem(7, "Pasta Alfredo", "Italian", 220.0),

FoodItem(8, "Tom Yum Soup", "Thai", 150.0)

def display_menu(self):

print("\nMenu:")

cuisines = set(item.cuisine for item in self.items)

for cuisine in cuisines:

print(f"\n{cuisine} Cuisine:")

for item in self.items:

if item.cuisine == cuisine:

print(f"{item.id}. {item.name} - ₹{item.price}")

class UserManager:

def __init__(self):

self.users = {}

def add_user(self, username, password):

self.users[username] = {"password": password, "orders": []}

def authenticate_user(self, username, password):

if username in self.users and self.users[username]["password"] == password:

return True

return False

def get_user_orders(self, username):

return self.users[username]["orders"]
def add_order_to_user(self, username, order):

self.users[username]["orders"].append(order)

def place_order(username, menu, user_manager):

order = Order(username)

while True:

menu.display_menu()

choice = input("Enter the item number to add to the order (0 to finish): ")

if choice == '0':

break

try:

choice = int(choice)

item = next((i for i in menu.items if i.id == choice), None)

if item:

quantity = int(input("Enter the quantity: "))

order.add_item(item, quantity)

print(f"{quantity} {item.name}(s) added to the order.")

else:

print("Invalid choice. Please enter a valid item number.")

except ValueError:

print("Invalid input. Please enter a number.")

return order

def display_order_history(username, user_manager):


orders = user_manager.get_user_orders(username)

if not orders:

print("\nNo order history.")

else:

print("\nOrder History:")

for i, order in enumerate(orders, 1):

print(f"\nOrder {i} - Order ID: {order.order_id}, Total: ₹{order.calculate_total()}")

for item in order.items:

print(f"{item['quantity']} {item['item'].name}(s) - ₹{item['item'].price} each")

def main():

menu = Menu()

user_manager = UserManager()

while True:

print("\nOptions:")

print("1. Log in")

print("2. Register")

print("3. Exit")

option = input("Enter your choice: ")

if option == '1':

username = input("Enter your username: ")

password = input("Enter your password: ")

if user_manager.authenticate_user(username, password):

order = place_order(username, menu, user_manager)


user_manager.add_order_to_user(username, order)

print(f"Order placed. Order ID: {order.order_id}, Total: ₹{order.calculate_total()}")

else:

print("Invalid username or password. Please try again.")

elif option == '2':

username = input("Enter a new username: ")

password = input("Enter a password: ")

if username not in user_manager.users:

user_manager.add_user(username, password)

print("User registered successfully.")

else:

print("Username already exists. Please choose another.")

elif option == '3':

print("Exiting the system. Thank you!")

break

else:

print("Invalid option. Please enter a valid choice.")

if __name__ == "__main__":

main()

You might also like