码迷,mamicode.com
首页 > 其他好文 > 详细

shopping_car练手程序

时间:2016-08-23 14:31:58      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

这个code是一个简单的模拟商城的购物车的简单程序。输入薪资,选择购买的商品序号,会计算出余额,当余额不足时,提示所欠余额。

  

#__author__:"Jay guo"
#__date__:2016/8/22
counter = 0
a = [["iphone",5800],["mac book",9000],["coffee",32],["python book",80],["bicyle",1500]]
for i in a:
    counter += 1
    print (counter,end = ".")
    for j in i:
        print (j,end = " ")
    print ()
  #  print (counter,".",i)
salary = int(input("input your salary>>: "))
list = []
list1 = []
center = salary
while True:
    choice = input("plz choice >>:")
    if choice.isdigit():
        choice = int(choice)
        if(choice > len(a)):
            print ("没有该商品")
            continue
        if  a[choice-1][1]> center:
            print ("余额不足",center-a[choice-1][1],"")
        else:
            center = center - a[choice-1][1]
            list.append(a[choice-1])
            print ("您的%s购买成功还余%d元" %(a[choice-1][0],center))
    elif choice == "quit":
        for j in list:
            if list.count(j) > 1:
                for i in list1:
                    if i == j:
                        break
                else:
                    print (j,list.count(j))
                list1.append(j)
            else:
                print (j,1)
        print ("所剩余额为:%s 元" %center)
        break
    else:
        print ("输入格式错误")

 

shopping_car练手程序

标签:

原文地址:http://www.cnblogs.com/276381225q/p/5798906.html

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