3.购物车

来源:互联网 发布:webview 加载js 阻塞 编辑:程序博客网 时间:2024/06/15 18:58
product_list = [    ('iphone', 5800),    ('Mac Pro', 9800),    ('Bike', 800),    ('Watch', 10600),    ('Cofee', 31),    ('python', 120)]shopping_list = []def panduan(string):    s = str(string)    if s.count('.') == 1:        sl = s.split('.')        left = sl[0]        right = sl[1]        if left.isdigit() & right.isdigit():            return True        else:            return False    elif s.isdigit():        return True    else:        return Falsesalary = input("Input your salary:")if panduan(salary):    salary = float(salary)    while True:        for index, item in enumerate(product_list):            print(index, item)        user_choose = input("请输入商品编号:")        if user_choose.isdigit():            user_choose = int(user_choose)            if user_choose < len(product_list) and user_choose > 0:                s = product_list[user_choose]                if s[1] <= salary:                    shopping_list.append(s)                    salary -= s[1]                    print('added %s into your shopping cart ,your balance is \033[31;1m%s\033[0m' % (s[0], salary))                else:                    print('your salary can not affrond')            else:                print('您输入的商品编号不存在...')        elif user_choose == 'q':            print('----------shopping list-------------')            for i in shopping_list:                print(i)            print('余额:', salary)            print('------------------------------------')            exit()        else:            print('无效编号!!!')
原创粉丝点击