首页 > 技术文章 > python 小程序—循环和列表训练

luckycn 2017-05-04 11:19 原文



a=input('please input your salary:') purchase=[] while True: products=[[1,'iphone',5800],[2,'book',50],[3,'bike',800],[4,'coffee',40]] for i in products: print i b=raw_input('please input the thing what you want buy(put Q or q to end):') if b.upper()=='Q': break elif products[int(b)-1][2]>a: print 'your money is not enough,choose other' else: a=a-products[int(b)-1][2] purchase.append(products[int(b)-1]) print 'the next is what you have bought:' print 'your balance is %s'%a for i in purchase: print i

 

运行结果:

 

推荐阅读