首页 > 代码库 > Python小程序之购物车
Python小程序之购物车
1 goods = [ 2 (‘IPhone‘,5888), 3 (‘Mac Pro‘,12888), 4 (‘iWatch‘,2888), 5 (‘Bike‘,888), 6 (‘Cofe‘,16), 7 (‘Book‘,85) 8 ] 9 money = int(input("Please Input your Money:")) 10 buylist = [] 11 while True: 12 print(‘商品列表‘.center(30,‘-‘)) 13 for index,items in enumerate(goods): 14 name,price = items 15 print(index,name,price) 16 user_choice = input(‘Please input your choice:‘) 17 if user_choice.isdigit(): 18 user_choice = int(user_choice) 19 if user_choice < len(goods) and user_choice >= 0: 20 if money > goods[user_choice][1]: 21 money -= goods[user_choice][1] 22 buylist.append((‘%s,%s‘) % (goods[user_choice][0],goods[user_choice][1]) ) 23 else: 24 choice = input(‘The money are not enough,Continue? ‘) 25 if choice == ‘y‘: 26 continue 27 else: 28 print(‘您的购物车有:‘) 29 for info in buylist: 30 print(info) 31 exit(‘您的余额为: %s ‘ % money) 32 else: 33 print(‘input Error, retry‘) 34 continue 35 elif user_choice == ‘q‘: 36 if len(buylist) == 0: 37 exit(‘您未购买任何东西,您的余额还有:%s‘ % money) 38 else: 39 print(‘您的购物车有:‘) 40 for info in buylist: 41 print(info) 42 print(‘您的余额为: %s ‘ % money) 43 else: 44 print(‘\033[31;1mInput Error,retry\033[0m‘) 45 continue
Python小程序之购物车
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。