基于Python下的手机销售管理系统(用类做)

要求如下:

手机销售系统

    手机品牌    手机价格    库存数量
     vivoX9           2798          25
     iphone7(32G)       4888          31
     iphone7(128G)       5668          22
     iphone7P(128G)       6616          29
     iphone6(16G)       3858          14
     ...
功能要求:
    四个选项:
        1.查看所有手机品牌
            1.vivoX9 
            2.iphone7(32G)
            ......
                分支选项:
                1.选择产品序号查看详情(根据序号输出产品名称,价格,库存)
                    1.购买(库存数量-1,库存为0时,删除该产品)
                    2.返回
                2.返回
        2.更改产品库存信息
            1.添加新产品(添加新产品,包括产品名称、价格、库存)
            2.修改原有产品
              输出所有产品信息
              1.根据选择序号进行修改
              2.返回
        3.移除产品库存信息
            1.查看所有产品,根据序号移除
            2.移除所有产品
            3.返回
        4.退出程序

具体实现其功能的代码如下:

# 数据模型类
class Phone(object):
    '''
    手机类
    '''
    def __init__(self,name,price,count):
        self.name = name
        self.price = price
        self.count = count

# 用来操作整个程序执行逻辑
class PhoneShop(object):
    '''
    商店类
    '''
    def __init__(self):
        # phone1存储所有手机对象
        self.phones = []

    def buy_phone(self):
        print('*  请输入产品信息:')
        name = print('*  请输入手机名称:')
        price = print('*  请输入手机价格:')
        count = print('*  请输入手机库存:')
        # 创建一个新的phone对象
        phone = Phone(name=name, price=price, count=count)
        # 将phone对象添加到phones列表中
        self.phones.append(phone)
        print(self.phones)

        print('*  选择产品序号查看详情')
        print('*  1.购买')
        print('*  2.返回')
        shop = int(input('*  请选择您的操作:'))
        while shop < 1 or shop > 2:
            shop = int(input('*  选项不存在,请重新选择:'))
        if shop == 1:
            print('*  购买成功!')
        else:
            pass

    def xiugia(self):
        self.query_all()
        idx = int(input('*  请输入你要修改的序号:'))
        phone = Phone[idx - 1]
        new_name = input('*  请输入修改的名称:')
        new_price = input('*  请输入修改的价格:')
        new_count = input('*  请输入修改的库存:')
        phone.name = new_name
        phone.price = new_price
        phone.count = new_count

    def run(self):
        '''
        启动程序
        :return:None
        '''
        while True:
            print('*  欢迎使用手机销售管理系统')
            print('*  1.查看所有')
            print('*  2.添加手机')
            print('*  3.删除手机')
            print('*  4.退出程序')
            select = int(input('*  请选择您的操作:'))
            while select < 1 or select > 4:
                select = int(input('*  选项不存在,请重选:'))
            if select == 1:
                self.change()
            elif select == 2:
            #     调用添加手机函数
                self.buy_phone()
            elif select == 3:
                pass
            else:
                print('*  感谢您的使用,欢迎下次再来!')
                break

    def yichu(self):
        print('*  1.根据序号移除')
        print('*  2.移除所有产品')
        print('*  3.返回')
        a = int(input('*  请选择您的操作:'))
        while a <1 or a > 3:
            a = int(input('*  选项不存在,请重选'))
        if a == 1:
            pass
        elif a == 2:
            is_del = int(input('*  是否移除所有产品?y/n:'))
            if is_del == 'y':
                phone_list.pop()
                print('*  删除成功!')
            else:
                return
        else:
             return

    def query_all(self):
        for phone in self.phones:
            print(phone.name,phone.price,phone.count)

    def change(self):
        for phone in self.phones:
            print(phone.name,phone.price,phone.count)

        print('*  1.添加新产品')
        print('*  2.修改原有产品')
        result = int(input('*  请选择您的操作:'))
        while result < 1 or result > 2:
            result = (input('*  选项不存在,请重新选择:'))
        if result == 1:
            self.qurey_all()
        else:
            print('*  输出所有产品信息')
            print('*  1.根据选择序号进行修改')
            print('*  2.返回')
            index = int(input('*  请输入您的选择:'))
            while index < 1 or index > 2:
                index = int(input('*  选项不存在,请重新选择:'))
            if index == 1:
                pass
            else:
                return


phone_list = []

shop = PhoneShop()
shop.run()
shop.yichu()

程序运行出来之后的界面如下:

然后根据提示继续操作

猜你喜欢

转载自blog.csdn.net/qq_42598133/article/details/81098535