• Python超市商品管理系统


    系统需要用户先登录,再进行操作,其中包含一下功能菜单

    1、显示商品列表
    2、增加商品信息
    3、删除商品
    4、设置商品折扣
    5、修改商品价格信息
    6、退出

    a、使用列表嵌套字典的方式保存用户数据(包含用户名、密码、姓名);
    b、使用列表嵌套字典的方式保存商品数据(包含编号、名称、价格、折扣);
    c、编写用户登录的函数,返回登录结果
    d、循环提示菜单,业务完毕时返回主菜单,退出时回到登录页面
    e、将功能菜单中的业务功能各自编写到函数中
    f、用户选择不同业务编号时,调用已经

    # -*- coding:utf-8 -*-
    # @Author : 小红牛
    # 微信公众号:WdPython
    # a、使用列表嵌套字典的方式保存用户数据(包含用户名、密码、姓名)
    user1 = {"用户名": "111", "密码": "123", "姓名": "刘皇叔"}
    user2 = {"用户名": "222", "密码": "123", "姓名": "李狗蛋"}
    userlist = [user1, user2]
    
    # b、使用列表嵌套字典的方式保存商品数据(包含编号、名称、价格、折扣)
    commodity1 = {"编号": "1001", "名称": "苹果", "价格": 8, "折扣": 1}
    commodity2 = {"编号": "1002", "名称": "香蕉", "价格": 6, "折扣": 1}
    commodity3 = {"编号": "1003", "名称": "西瓜", "价格": 5, "折扣": 1}
    commoditylist = [commodity1, commodity2, commodity3]
    
    
    # 登录
    def login():
        msg = "失败"
        count = 0
        while True:
            uname = input("请输入账号:")
            upwd = input("请输入密码:")
            for user in userlist:
                if uname == user["用户名"] and upwd == user["密码"]:
                    print("登录成功,欢迎你", user["姓名"])
                    msg = "成功"
                    break
            if msg == "失败":
                count += 1
                if count < 3:
                    print("用户名密码错误!请重新登录", "输入第", count, "次")
                else:
                    print("用户已锁定!")
                    break
            else:
                break
        return msg
    
    
    # 1、显示商品列表
    def showProduct():
        print("----------产品信息----------")
        print("-编号----名称----价格----折扣-")
        for commodity in commoditylist:
            print("-" + commodity["编号"] + "----" + commodity["名称"] + "-----" + str(commodity["价格"]) + "-----" + str(
                commodity["折扣"]))
        print("----------------------------")
    
    
    # 2、增加商品信息
    def addProduct():
        list1 = []
        for num in commoditylist:
            list1.append(int(num["编号"]))
        num = str(max(list1) + 1)
        print("----------添加商品信息----------")
        mc = input("请输入产品名称:")
        jg = float(input("请输入产品价格:"))
        zk = 1
        newProduct = {"编号": num, "名称": mc, "价格": jg, "折扣": zk}
        commoditylist.append(newProduct)
        print("商品" + mc + "添加成功")
        print("-------------------------------")
        showProduct()
    
    
    # 3、删除商品
    def delproduct():
        showProduct()
        while True:
            msg = 0
            num = input("请输入要删除商品的编号")
            for product in commoditylist:
                if num == product["编号"]:
                    print("商品", product["名称"], "正在删除")
                    commoditylist.remove(product)
                    print("删除成功!")
                    msg = 1
                    break
            if msg == 0:
                print("输入的产品编号不正确,请重新输入")
                jx = input("取消输入请按1,继续请按2")
                if jx == 1:
                    break
                elif jx == 2:
                    continue
                else:
                    print("输入错误请重新输入")
            else:
                showProduct()
                break
    
    
    # 4、设置商品折扣
    def setDiscount():
        while True:
            mag = 0
            name = input("请输入要设置折扣的商品名称")
            for x in commoditylist:
                if name == x["名称"]:
                    zk = float(input("请输入要设置产品的折扣(0.1-1)"))
                    x["折扣"] = zk
                    print(x["名称"] + "的折扣为:" + str(zk))
                    mag = 1
                    break
            if mag == 0:
                print("输入的商品名称不存在,请重新输入")
                jx = input("取消输入请按1,继续请按2")
                if jx == "1":
                    break
                elif jx == "2":
                    continue
                else:
                    print("输入错误请重新输入")
            else:
                showProduct()
                break
    
    
    # 5、修改商品价格信息
    def setPrice():
        while True:
            mag = 0
            num = input("请输入要设置价格的商品编号")
            for x in commoditylist:
                if num == x["编号"]:
                    jg = float(input("请输入要设置产品价格"))
                    x["价格"] = jg
                    print(x["名称"] + "的价格为:" + str(jg))
                    mag = 1
                    break
            if mag == 0:
                print("输入的商品编号不存在,请重新输入")
                jx = input("取消输入请按1,继续请按2")
                if jx == "1":
                    break
                elif jx == "2":
                    continue
                else:
                    print("输入错误请重新输入")
            else:
                showProduct()
                break
    
    
    # 6、根据价格排序显示商品列表
    def sort():
        choice = int(input("请选择升序或者降序(1、升序 2、降序)"))
        clist = []
        for commodity in commoditylist:
            clist.append(commodity["价格"])
        clist = list(set(clist))
        if choice == 1:
            newlist = sorted(clist)
            for price in newlist:
                for product in commoditylist:
                    if price == product["价格"]:
                        print("-" + product["编号"] + "----" + product["名称"] + "-----" + str(product["价格"]) + "-----" + str(
                            product["折扣"]))
        else:
            newlist = sorted(clist, reverse=True)
            for price in newlist:
                for product in commoditylist:
                    if price == product["价格"]:
                        print("-" + product["编号"] + "----" + product["名称"] + "-----" + str(product["价格"]) + "-----" + str(
                            product["折扣"]))
    
    
    # 主程序开始
    while True:
        result = login()
        if result == "成功":
            while True:
                print("*********主菜单*********")
                print("1、显示商品列表")
                print("2、增加商品信息")
                print("3、删除商品")
                print("4、设置商品折扣")
                print("5、修改商品信息")
                print("6、根据价格排序商品")
                print("7、退出")
                print("*********************")
                choice = int(input("请输入您的选项(1-7)"))
                if choice == 1:
                    showProduct()
                elif choice == 2:
                    addProduct()
                elif choice == 3:
                    delproduct()
                elif choice == 4:
                    setDiscount()
                elif choice == 5:
                    setPrice()
                elif choice == 6:
                    sort()
                elif choice == 7:
                    print("------------系统已退出")
                    break
                else:
                    print("没有此功能请重新输入")
                    continue
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201

    完毕!!感谢您的收看

    ----------★★历史博文集合★★----------

    我的零基础Python教程,Python入门篇 进阶篇 视频教程 Py安装py项目 Python模块 Python爬虫 Json Xpath 正则表达式 Selenium Etree CssGui程序开发 Tkinter Pyqt5 列表元组字典数据可视化 matplotlib 词云图 Pyecharts 海龟画图 Pandas Bug处理 电脑小知识office自动化办公 编程工具 NumPy Pygame

  • 相关阅读:
    docker-compose部署mysql
    【数据库】MySQL分页查询
    Mac(M1芯片)安装多个jdk,Mac卸载jdk
    通过QGIS下载高程数据并进行矢量数据高程的计算
    docker安装elasticSearch+kibana
    Linux线程同步对象:互斥体、信号量、条件变量、读写锁
    鸿鹄工程项目管理系统em Spring Cloud+Spring Boot+前后端分离构建工程项目管理系统
    那些年我们追过的Devops
    计算机毕业设计Python+Django的优智学直播授课平台系统(源码+系统+mysql数据库+Lw文档)
    API 自动化测试难点总结与分享
  • 原文地址:https://blog.csdn.net/gxz888/article/details/137375003