标签:ems coding pre lis 图片 选择 money close logs
需求流程图:
需求代码:
#_*_ coding:utf-8 _*_ total_money = int(input(‘请输入您的预算金额:‘)) total_list = [] while total_money > 0: f = open(‘shopping_list‘,‘r‘) print(‘‘‘ THE SHOPPING LIST name money ‘‘‘) #清单模板 shopping_list= {} for i in f.readlines(): (k,v) = i.strip().split() shopping_list[k] = v print(k,v) #打印购物清单 f.close() min_money = int(min(shopping_list.items(),key=lambda x:x[1])[1]) #取商品的最小金额 if total_money < min_money: #比较输入金额 print(‘sorry!你的余额不足,不能购买任何商品!!Bye!~‘) break if total_money > 0: choice_name = input(‘请选择你要购买的商品名称:‘) total_money = total_money - int(shopping_list[choice_name]) if total_money > 0: #判断输入的商品金额是否超出余额 print(‘您购买的商品是:%s,剩余金额为:%d‘ %(choice_name,total_money)) next_time = input(‘是否继续购买:Y/N?‘) total_list.append(choice_name) if next_time == ‘y‘: continue else: break else: print(‘您的金额不足!‘) break print(‘您购买的商品为:%s‘ %total_list)
标签:ems coding pre lis 图片 选择 money close logs
原文地址:http://www.cnblogs.com/fighting-python/p/7942003.html