码迷,mamicode.com
首页 > 编程语言 > 详细

Python购物车

时间:2017-03-29 21:00:08      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:xiaomi   inpu   mac   输入   python   int   else   list   ==   

product_list = [
    [Iphone,5888],
    [Mac Air,8000],
    [XiaoMi,19.9],
    [coffee,30],
    [Tesla,820000],
    [Bike,700],
    [Cloth,200],   ]
l=[]
shop_car=[]
salary=int(input("请输入您的工资: "))
while True:
    index=0
    for i in  product_list:
        print(index,i)
        index+=1
    choice=input("请输入商品编号 w保存,q 退出: ")
    if choice.isdigit():
        choice=int(choice)
        if  choice > 0 and choice <= len(product_list):
            product=product_list[choice]
            if salary >= product[1]:
                shop_car.append(product)
                salary -= product[1]
            else:
                print("余额不足")
        else:
            print("您输入的商品编号不存在")

    elif choice == w:
        print("---已经购买的商品列表---")
        l=[]
        for i in shop_car:
            if i not in l:
                l.append(i)
                l.append(shop_car.count(i))
        print(l)

        print("您的余额 %s" % salary)
        print("end-----------")
        break
    else:
        exit("退出程序")

 

Python购物车

标签:xiaomi   inpu   mac   输入   python   int   else   list   ==   

原文地址:http://www.cnblogs.com/sss4/p/6641610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!