清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #!/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" |