首页 > 编程语言 > 详细

python 用列表实现简单购物功能

时间:2017-08-03 19:37:51      阅读:230      评论:0      收藏:0      [点我收藏+]
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 用列表实现简单购物功能

原文:http://www.cnblogs.com/xiaoxinzang/p/7281276.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!