标签:python and 选择 == lis 商品 opp name git
goods_list = [ {‘name‘: ‘苹果‘, ‘price‘: ‘10‘}, {‘name‘: ‘香蕉‘, ‘price‘: ‘15‘}, {‘name‘: ‘菠萝‘, ‘price‘: ‘20‘}, {‘name‘: ‘西瓜‘, ‘price‘: ‘25‘}, {‘name‘: ‘葡萄‘, ‘price‘: ‘30‘}, ] shopping_car = {} print("欢迎光临小粉嫩水果店!") money = input("请拿出您的银子:") if money.isdigit() and int(money) > 0: flag = True while flag: for i, k in enumerate(goods_list): print(‘序号{}, 商品{}, 价格{}‘.format(i, k[‘name‘], k[‘price‘])) choose = input("请输入您选择的序号:") if choose.isdigit() and int(choose) < len(goods_list): num = input("请输入您要购买商品的个数:") if num.isdigit(): if int(money) > int(goods_list[int(choose)][‘price‘]) * int(num): money = int(money) - int(goods_list[int(choose)][‘price‘]) * int(num) if goods_list[int(choose)][‘name‘] in shopping_car: shopping_car[goods_list[int(choose)][‘name‘]] = shopping_car[goods_list[int(choose)][‘name‘]] + int(num) else: shopping_car[goods_list[int(choose)][‘name‘]] = int(num) print("购物车中的商品有{}, 您的余额为{}".format(shopping_car, money)) print("如果您想离开请按Q或q,欢迎下次光临!") else: print("穷鬼,滚去敲代码赚钱!") break else: print("请输入数字,谢谢!") elif choose.upper() == "Q": flag = False print("您当前的购物车为{},余额为{}".format(shopping_car, money)) else: print("傻逼,输入数字!!!")
标签:python and 选择 == lis 商品 opp name git
原文地址:https://www.cnblogs.com/-1206-/p/9484526.html