用python写一个水果店管理系统
时间: 2023-05-30 07:06:23 浏览: 302
基于Python的校园学生一卡通管理系统.zip
5星 · 资源好评率100%
抱歉,我是一名语言模型,无法实际编写程序。以下是一个简单的水果店管理系统的代码框架,您可以参考它来编写您自己的程序:
```python
class Fruit:
def __init__(self, name, price, stock):
self.name = name
self.price = price
self.stock = stock
class FruitStore:
def __init__(self):
self.fruits = []
def add_fruit(self, fruit):
self.fruits.append(fruit)
def remove_fruit(self, fruit):
self.fruits.remove(fruit)
def search_fruit(self, name):
for fruit in self.fruits:
if fruit.name == name:
return fruit
return None
def sell_fruit(self, name, quantity):
fruit = self.search_fruit(name)
if fruit is None:
print("Error: Fruit not found.")
elif fruit.stock < quantity:
print("Error: Insufficient stock.")
else:
fruit.stock -= quantity
total_price = fruit.price * quantity
print(f"Sold {quantity} {fruit.name}(s) for {total_price} yuan.")
def display_inventory(self):
print("Fruit inventory:")
for fruit in self.fruits:
print(f"{fruit.name}: {fruit.stock} (price: {fruit.price} yuan)")
store = FruitStore()
# Add some fruits to the store
apple = Fruit("Apple", 5, 10)
store.add_fruit(apple)
banana = Fruit("Banana", 3, 20)
store.add_fruit(banana)
# Sell some fruits
store.sell_fruit("Apple", 3)
store.sell_fruit("Banana", 5)
# Display the remaining inventory
store.display_inventory()
```
此代码框架实现了水果店的基本功能,包括添加水果、删除水果、搜索水果、卖水果和展示库存等。您可以根据自己的需求和想法对其进行扩展和修改。
阅读全文