简单电商购物程序(续1)

#1)电商购物会员登录和会员注册;会员有属性:姓名、性别、登录账号、密码、累计积分值、会员资格;

#会员资格分为:金钻、银钻、高级、普通等级别。

#2)完善商品库:设置购买该商品可以获得的积分,要求不同会员等级赠送的积分不同

#3)建立获得不同级别会员资格所需的积分数标准规则,会员达到一定积分时,就可以升级会员资格,成为更高级别的会员资格。

#4)增加会员购买商品获得积分的记录更新,更新积分的同时根据累计的积分是否达到相应会员资格级别,更新会员资格信息。
def logon(tename,tepassword,credit):
    if tename == logname and tepassword ==logpassword:
        print("------------------------")
        print("欢迎您  "+name+" 使用电商购买系统")
        print("您的积分:"+str(credit)+" 等级为:"+Membertype(credit))
    else:
        print("账号密码错误请重新输入 或 注册账号")

menbertypr = "普通级别"
def Membertype(credit):
    if credit<100:
        menbertypr = "普通级别"
    elif 100<=credit<200:
        menbertypr = "高级级别"
    elif 200<=credit<300:
        menbertypr = "银钻级别"
    elif 300<=credit<400:
        menbertypr = "金钻级别"
    else:
        menbertypr = "终身VIP级别"

    return menbertypr


cre=0
def like():
    i = 2  # 为了通过修改i 退出多重循环
    allChoice = []
    while (i):
        for num in range(len(shop)):  # 打印商品列表
            print(str(shop[num][0]).ljust(5), shop[num][1].ljust(20), str(shop[num][2]).ljust(10),
                  str(shop[num][3]).ljust(10))
        choice = input("请输入要加入购物车的商品编号:")
        choice = [int(it) for it in choice.split(' ')]
        allChoice += choice  # choice是单次选择的商品列表,allchoice是所有选择的商品列表
        while (1):
            total = 0
            total1 = 0
            global cre
            credit = cre
            choiceSet = set(allChoice)  # 转换成集合,便于不重复计数
            for it in choiceSet:
                print(shop[it - 1][0], shop[it - 1][1], shop[it - 1][2], '*', allChoice.count(it))
                total += shop[it - 1][2] * allChoice.count(it)

            print("总计:", total, )
            print("---------------------------------\n"
                  "1:继续选购 2:整理购物车 Buy:结算\n")
            option = input("请选择:")
            if option == '1':
                break
            elif option == '2':
                item_num = int(input("请输入要删除的商品:"))
                allChoice.remove(item_num)  # 每次只会删除一个元素
                continue
            if option == 'Buy':
                for it in choiceSet:
                    print("*************结算**************")
                    print(shop[it - 1][0], shop[it - 1][1], shop[it - 1][2], '*', allChoice.count(it))
                    total1 += shop[it - 1][2] * allChoice.count(it)
                    credit += shop[it - 1][3] * allChoice.count(it)
                print("总计:", total1, "积分为:", credit, "会员等级:", Membertype(credit))
                print("-----信息更新成功!!!------")
                print("尊敬的",name,"性别",sex)
                print("您的积分:" + str(credit) + " 等级为:" + Membertype(credit))
                print("-----感谢您的使用,再见!------")
                cre =credit
                i =0
                break
            else:
               print("输入错误请重新输入!")


shop = {}
a = 1
shop = [['1', '奔驰', 150000, 100], ['2', '宝马', 100000, 100], ['3', '越野', 28000, 100],
            ['4', '沃尔沃', 12000, 100],
            ['5', '野马', 450000, 50], ['6', '奥迪', 230000, 100], ['7', '红旗', 100000, 100]]
while (a):

    a=input("请输入“登录”或“注册”:")
    if a=="注册":
        name=input("请输入姓名:")
        sex = input("请输入性别:")
        logname = input("请输入账号:")
        logpassword = input("请输入密码:")
        credit=cre=0
    elif a=="登录":
        tename = input("请输入账号:")
        tepassword = input("请输入密码:")
        try:
            credit=cre
            logon(tename,tepassword,credit)
            like()
        except:
            print("请先注册帐号!")

  

 

posted @ 2019-05-29 10:58  Locog  阅读(103)  评论(0编辑  收藏  举报