使用python实现超市管理系统(粗略)

文章描述了一个基于Python编写的简易购物系统,包括用户注册、登录验证、购物结算等功能。
摘要由CSDN通过智能技术生成
import random
while 1:
    print("***************购物系统***************")
    print("              1.注册用户              ")
    print("              2.登录系统              ")
    print("              3.退出                 ")
    print("***************购物系统***************")
    num=int(input("请选择,输入数字:"))
    if num==1:
        print("***********欢迎进入注册系统************")
        member="null"
        while member=="null":
            member="ture"
            name1 = input("请输入用户名:")
            password1 = input("请输入密码:")
            password2 = input("请再次输入密码:")
            telephone = input("请输入电话号码:")
            if len(name1) < 3:
                print("用户名的长度不能小于3.")
                member = "null"
                continue
            if len(password1) < 6:
                print("密码长度不能小于6")
                member = "null"
                continue
            if password1[0] not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789":
                #password1[0] not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789":可以等价于一个函数:
                print("密码由数字或字母构成。")
                member = "null"
                continue
            if password1 != password2:
                print("两次的输入密码不相同。")
                member = "null"
                continue
            if telephone[0] not in "1" or len(telephone) != 11:
                print("无效的手机号码。")
                member = "null"
                continue
        else:
            print("**注册成功!")
            huiyuan=random.randint(1000,10000)
            print("**会员ID:C-%d"%(huiyuan))
            print("**会员用户名:%s"%name1)
        continue
    if num==2:
        point  = 0
        member = "null"
        while point < 3:
            point+=1
            if member=="null":
                name=input("请输入用户名:")
                password=input("请输入密码:")
                if name==name1 and password==password1 :
                    while 1:
                        print("*************欢迎进入购物系统*************")
                        print("            1.客户信息管理              ")
                        print("            2.购物结算                 ")
                        print("            3.真情回馈             ")
                        print("            4.注销                ")
                        print("*************欢迎进入购物系统*************")
                        num1 = int(input("请选择,输入数字:"))
                        if num1==1:
                            print("该用户是本店的会员:")
                        elif num1 == 2:
                            a = "购物系统"
                            b = "购物清单"
                            print(f"{a:*^40}")
                            print(f"{'商品编号': <8}", f"{'商品名称': <8}", f"{'商品价格': ^8}")
                            goship = []
                            num = 0.0
                            while 1:
                                products = [[1, "XX手机", 4480.00], [2, "XXX电脑", 6480.00], [3, "XXX耳机", 480.00],
                                            [4, "XX运动鞋", 280.00],
                                            [5, "XXX钢笔", 18.00]]
                                for i in range(len(products)):
                                    print(f"{products[i][0]: ^5}", f"{products[i][1]: ^18}", f"{products[i][2]:.2f}")
                                business = input("请选择您要购买的商品(结束购物请输入q):")
                                if business == "q":
                                    print(f"{b:*^40}")
                                    print(f"{'商品名称': <8}", f"{'商品价格': <8}", f"{'商品数量': ^8}",
                                          f"{'商品总价': ^8}")
                                    for i in range(len(goship)):
                                        print(f"{goship[i][0]: ^5}", f"{goship[i][1]:11.2f}", f"{goship[i][2]: ^15}",
                                              f"{goship[i][3]:8.2f}")
                                        num = num + goship[i][3]
                                    print("你的购物总金额是:%.2f元" % num)
                                    break
                                number = int(input("请选择购买的数量:"))
                                pro = [products[int(business) - 1][1], products[int(business) - 1][2], number,
                                       products[int(business) - 1][2] * number]
                                goship.append(pro)
                        elif num1==3:
                            print("感谢小伙伴们对我们超市的使用,暂时还未有活动敬请期待!")
                        elif num1==4:
                            print("感谢小伙伴们对我们超市的使用,再见!")
                            member="no"
                            break
                    break
                else:
                    print("用户名或密码错误,请重新登录!")
        else:
            print("登录超过三次,请稍后再试。")
    elif num==3:
        print("***************购物系统***************")
        print("              谢谢光临             ")
        print("***************购物系统***************")
        break
    else:
        print("***************购物系统***************")
        print("            选择有误,再见!             ")
        print("***************购物系统***************")
        break
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值