清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#!/usr/bin/env python import sys '''简单的购物菜单,根据输入的金额,减去选择的商品得到剩下的金额, 一旦省下的金额小于所有的商品价格,提示余额不足''' product = [] price = [] f = open('act.txt') for line in f.readlines(): p = line.split()[0] pp = line.split()[1] product.append(p) price.append(int(pp)) f.close() shop_list =[] while True: try: money = int(raw_input("How money you have:")) break except ValueError: print "wrong enter" while True: for p in product: print p,price[product.index(p)] print "buy sth~" choose = raw_input("please enter which one you buy:").strip() if choose == "quit": sys.exit() if choose in product: product_price = price[product.index(choose)] if money > product_price: shop_list.append(choose) print "Add %s into your basket" % choose money = money - product_price print "you have %s money to buy sth" % money else: if money < min(price): print "go home baby,there is no money to afford sth" print "%s to buy successful" % shop_list sys.exit() else: print "you can't afford this product"