0% found this document useful (0 votes)
29 views3 pages

Level 1

Uploaded by

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

Level 1

Uploaded by

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

class FoodOrderingSystem:

def __init__(self):
self.menu = {
'Pizza': 10.99,
'Burger': 5.99,
'Pasta': 7.99,
'Salad': 4.99,
'Soda': 1.99
}
self.order = []
self.total_cost = 0

def display_menu(self):
print("\n--- Menu ---")
for item, price in self.menu.items():
print(f"{item}: ${price:.2f}")

def take_order(self):
while True:
self.display_menu()
choice = input("\nEnter the name of the food to order (or 'done' to
finish): ").title()

if choice == 'Done':
break
elif choice in self.menu:
self.order.append(choice)
self.total_cost += self.menu[choice]
print(f"{choice} added to your order.")
else:
print("Invalid choice. Please try again.")

def show_order(self):
if not self.order:
print("\nYour order is empty!")
else:
print("\n--- Your Order ---")
for item in self.order:
print(item)
print(f"Total cost: ${self.total_cost:.2f}")

def checkout(self):
self.show_order()
if self.order:
payment = float(input("\nEnter payment amount: $"))
if payment >= self.total_cost:
change = payment - self.total_cost
print(f"Thank you for your order! Your change is ${change:.2f}")
else:
print("Insufficient funds! Please enter a valid payment amount.")
else:
print("No items ordered. Please order something first.")

if __name__ == "__main__":
system = FoodOrderingSystem()

print("Welcome to the Food Ordering System!")

system.take_order()
system.checkout()
How the Code Works:
Menu Initialization: The FoodOrderingSystem class is initialized with a dictionary
of food items and their prices.
Display Menu: The display_menu() method prints the available items and their
prices.
Taking Orders: The take_order() method allows the user to input the food items they
wish to order. The loop continues until the user types 'done'.
Show Order: The show_order() method displays all the items in the order and the
total cost.
Checkout: The checkout() method shows the final order, asks for payment, and checks
if the payment is sufficient. It also calculates the change if the payment is
higher than the total cost.
Example Output:
vbnet
Copy code
Welcome to the Food Ordering System!

--- Menu ---


Pizza: $10.99
Burger: $5.99
Pasta: $7.99
Salad: $4.99
Soda: $1.99

Enter the name of the food to order (or 'done' to finish): Pizza
Pizza added to your order.

Enter the name of the food to order (or 'done' to finish): Burger
Burger added to your order.

Enter the name of the food to order (or 'done' to finish): done

--- Your Order ---


Pizza
Burger
Total cost: $16.98

Enter payment amount: $20


Thank you for your order! Your change is $3.02
Features to Add for a Real-World System:
Database Integration: Store orders, items, and customer information in a database.
GUI: Create a graphical user interface (GUI) for a more user-friendly experience.
Payment Integration: Use payment gateway APIs (like Stripe or PayPal) for real
transactions.
Order History: Implement a system to save order history or allow reordering.
This is a simple console-based ordering system. You can expand it as per your
needs!

By messaging ChatGPT, you agree to our Terms and have read our Privacy Policy.
Don't share sensitive info. Chats may be reviewed and used to train our models.
Learn more
ChatGPT can make

You might also like