标签:
这个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 ("输入格式错误")
标签:
原文地址:http://www.cnblogs.com/276381225q/p/5798906.html