Python商品清單併購買小練習(列表等)
阿新 • • 發佈:2021-02-04
技術標籤:python
python 商品列表併購買清單
-- codeing = utf-8 --
@Time : 2021/2/3 16:55
@Author: lzp
@File : product_test.py
@Software: PyCharm
products = [["iphone",6888],["MacPro",14800],["小米6",2499],["COFFEE",31],["BOOK",60],["Nike",699]]
# 顯示商品列表
print ("-----商品列表----")
i = 0
for name in products:
print("%d %s %d"%(i,name[0],name[1]))
i += 1
# 詢問使用者待購買的物品,使用者按下q退出
j = 0
key = ""
list = [] #定義購物車清單表格
while key != "q":
number = input("請輸入商品編號:")
number = int(number)
list.append( products[number])
print("加入的商品為:",products[number])
j +=1
key = input("是否購買完成(按q結束購買):")
count = 0
print("\n---您購買的商品如下-----")
print("商品"," ","價格"," ","數量")
k = 0
biaodan = []
for name in products:
if name in list:
biaodan.append([name,list.count(name)])
for thing in biaodan:
print(thing[0][0]," ",thing[0][1]," ",thing[1])
count = count + int(thing[0][1])
print("總價為:", count)