用python 写一个餐馆菜单管理系统
时间: 2023-07-18 16:43:55 浏览: 135
基于python Django 餐馆点菜管理系统 完整代码 毕业设计
5星 · 资源好评率100%
好的,下面是一个简单的餐馆菜单管理系统的Python代码,包含添加菜品、查看菜单以及删除菜品等功能:
```python
menu = {}
def add_dish(name, price):
menu[name] = price
print(f"{name} added to the menu with a price of {price}.")
def view_menu():
print("MENU:")
for name, price in menu.items():
print(f"{name} - {price}")
def delete_dish(name):
if name in menu:
del menu[name]
print(f"{name} has been removed from the menu.")
else:
print(f"{name} is not in the menu.")
while True:
print("1. Add dish")
print("2. View menu")
print("3. Delete dish")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
name = input("Enter the name of the dish: ")
price = input("Enter the price of the dish: ")
add_dish(name, price)
elif choice == "2":
view_menu()
elif choice == "3":
name = input("Enter the name of the dish to delete: ")
delete_dish(name)
elif choice == "4":
print("Goodbye!")
break
else:
print("Invalid choice. Please enter a number from 1 to 4.")
```
以上代码实现了一个简单的餐馆菜单管理系统,用户可以通过输入不同的选项来实现添加菜品、查看菜单和删除菜品等功能。
阅读全文