标签:== money enum orm continue print ice dig 余额
li = [ {‘name‘:‘苹果‘,‘price‘:10}, {‘name‘:‘香蕉‘,‘price‘:20}, {‘name‘:‘西瓜‘,‘price‘:30} ] car = {} print(‘欢迎光临AJ小店‘) money = input(‘请输入您的余额‘) if money.isdigit() and int(money) > 0: money = int(money) while 1: for i,k in enumerate(li): print(‘序号{}\t商品{}\t价格{}‘.format(i+1,k[‘name‘],k[‘price‘])) choose = input(‘请输入您要选择商品的序号/按q退出‘) if choose.isdigit(): choose = int(choose) if choose > 0 and choose <= len(li): num = input(‘请输入您要购买商品的数量‘) if num.isdigit(): num = int(num) if li[choose-1][‘price‘] * num <= money: money = money - li[choose - 1][‘price‘] * num print(‘您的余额为{}‘.format(money)) if li[choose-1][‘name‘] in car: car[li[choose-1][‘name‘]] = car[li[choose-1][‘name‘]] + num else: car[li[choose-1][‘name‘]] = num else: print(‘余额不足,请重新输入或输入q退出‘) continue else: print(‘请重新输入‘) car[choose-1][‘商品‘] = li[choose-1] else: print(‘请输入正确的序号‘) elif choose == ‘q‘: break else: print(‘输入错误,请重新输入‘) else: print(‘对不起,请重新输入‘) for a,b in car.items(): print(‘商品{}\t数量{}‘.format(a,b))
标签:== money enum orm continue print ice dig 余额
原文地址:https://www.cnblogs.com/aj-AJ/p/10798469.html