Electricity supplier registration

def logon(tename, tepassword, credit):

    if tename == logname and tepassword == logpassword:

        print("------------------------")

        print ( "Welcome" + name + "using the purchasing system")

        print ( "Your points for:" + str (credit) + "rating:" + Membertype (credit))

    else:

        print ( "Please re-enter the wrong account password or account registration")

 

 

menbertypr = "vip1"

 

 

def Membertype(credit):

    if credit < 100:

        menbertypr = "vip1"

    elif 100 <= credit < 200:

        menbertypr = "vip2"

    elif 200 <= credit < 300:

        menbertypr = "vip3"

    elif 300 <= credit < 400:

        menbertypr = "vip4"

    else:

        menbertypr = "vip5"

 

    return menbertypr

 

 

cre = 0

 

 

def like():

    i = 2 # i to modify multiple exit loop

    allChoice = []

    while (i):

        for num in range (len (shop)): # Print the list

            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', '吉利', 100000, 100], ['2', '比亚迪', 80000, 100], ['3', '奇瑞', 68000, 100],

        ['4', '长城', 120000, 100],['5', '哈弗', 100000, 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("请先注册帐号!")

 

Guess you like

Origin www.cnblogs.com/kin9/p/10943073.html