码迷,mamicode.com
首页 > 其他好文 > 详细

购物车

时间:2018-10-09 16:16:06      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:out   [1]   ror   ast   []   mat   pam   tin   index   

list = [('iphone',12000),('iwatch',4200),('book',45),('water',3)]
shopp = []
money = input('input your money:')
if money.isdigit():
    money = int(money)
    while True:
        for index,i in enumerate(list):
            print(index+1,i)
        pamage = input('input shop number:')
        if pamage.isdigit():
            pamage = int(pamage)
            if pamage > 0 and pamage <= len(list):
                if pamage > len(list):
                    print('your num is out')
                else:
                    if list[pamage - 1][1] <= money:
                        money = money - list[pamage - 1][1]
                        print('------------------------------------------------')
                        print('your buy shop is \033[32;1m{shop}\033[0m,and your will out \033[31;1m{Money}\033[0m,and your money stay \033[42;1m{stay}\033[0m'.format(shop =list[pamage-1][0],Money=list[pamage-1][1],stay=money))
                        print('------------------------------------------------')
                        shopp.append(list[pamage-1][0])
                    else:
                        print('your money not inf')
            elif pamage > len(list):
                print('your number outing')
        elif pamage.lower() == 'q':
            for p in shopp:
                print('thid id your shop:\033[34;1m{0}\033[0m'.format(p))
            print('your money last \033[41;1m{0}\033[0m'.format(money))
            exit()
        else:
            print('input error,please checking')
else:
    print('please input number')

购物车

标签:out   [1]   ror   ast   []   mat   pam   tin   index   

原文地址:https://www.cnblogs.com/Arthur7/p/9760800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!