以下为一个简单的药品管理系统的Python代码示例:

"""
药品管理系统
"""

# 定义药品类
class Medicine:
    def __init__(self, name, price, quantity):
        self.name = name
        self.price = price
        self.quantity = quantity

# 定义药品管理系统类
class MedicineManagementSystem:
    def __init__(self):
        self.medicines = []

    # 添加药品
    def add_medicine(self, name, price, quantity):
        medicine = Medicine(name, price, quantity)
        self.medicines.append(medicine)

    # 删除药品
    def remove_medicine(self, name):
        for medicine in self.medicines:
            if medicine.name == name:
                self.medicines.remove(medicine)
                return True
        return False

    # 更新药品价格
    def update_price(self, name, price):
        for medicine in self.medicines:
            if medicine.name == name:
                medicine.price = price
                return True
        return False

    # 更新药品数量
    def update_quantity(self, name, quantity):
        for medicine in self.medicines:
            if medicine.name == name:
                medicine.quantity = quantity
                return True
        return False

    # 查找药品
    def search_medicine(self, name):
        for medicine in self.medicines:
            if medicine.name == name:
                return medicine
        return None

    # 显示所有药品
    def display_all_medicines(self):
        for medicine in self.medicines:
            print("药品名称:" + medicine.name + ",价格:" + str(medicine.price) + ",数量:" + str(medicine.quantity))

# 测试
system = MedicineManagementSystem()
system.add_medicine("阿莫西林", 15.0, 100)
system.add_medicine("板蓝根", 10.0, 200)
system.add_medicine("感冒灵", 20.0, 50)

system.display_all_medicines()

system.update_price("板蓝根", 12.0)
system.update_quantity("感冒灵", 100)

system.display_all_medicines()

medicine = system.search_medicine("阿莫西林")
if medicine:
    print("找到了药品:" + medicine.name)
else:
    print("药品不存在")

system.remove_medicine("板蓝根")
system.display_all_medicines()

运行结果:

药品名称:阿莫西林,价格:15.0,数量:100
药品名称:板蓝根,价格:10.0,数量:200
药品名称:感冒灵,价格:20.0,数量:50
药品名称:阿莫西林,价格:15.0,数量:100
药品名称:板蓝根,价格:12.0,数量:200
药品名称:感冒灵,价格:20.0,数量:100
找到了药品:阿莫西林
药品名称:阿莫西林,价格:15.0,数量:100
药品名称:感冒灵,价格:20.0,数量:100
写一个简单的药品管理系统

原文地址: https://www.cveoy.top/t/topic/but7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录