products = [['ipone',6888],['MacPro',14800],['小米6',2499],['coffee',31],['Book',60],['Nike',699]]
#第一问
print('-'*4 + '商品列表' + '-'*4)
index = 0
for shop in products:
print("%d\t%s\t%d"%(index,shop[0],shop[1]))
index += 1
print("================")
for i in range(6):
print("%d\t%s\t%d" % (i, products[i][0], products[i][1]))
i +=1
#第二问
list = [] #购物车列表
money = 0
i = 0
while i < len(products):
num = input("请输入您想购买商品的编号")
if num == 'q':
break
num = int(num)
list.append(products[num])
for shop in list:
money += shop[1]
print("购物车里有:",list,"共花费%d"%money)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)