首页 > 代码库 > python 用列表实现简单购物功能
python 用列表实现简单购物功能
import sys products = [‘PC‘,‘Coffee‘,‘TV‘,‘Car‘] shoplist = [] prices = [5000,50,800,20000] salary = input(‘please input your salary:‘) while True: for i in products: print ‘i‘,‘prices[products.index(i)]‘ choice = input‘please choose your need:‘ choice2 = choice.strip() if choice2 in products: product_price_index = products.index(choice2) product_price = prices[product_price_index] if salary > product_price: shoplist.append(choice) print‘%s has joined your shoppinglist‘ % choice2 salary = salary - product_price print‘your salary left:‘,salary else: if salary < min(prices) print‘Sorry,your salary cannot buy anything! ‘ print‘this is your shoppinglist:‘,shoplist sys.exit() else: print‘Sorry ,youcannot afford this product‘
python 用列表实现简单购物功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。