根据products列表写一个循环,不断询问用户想买什么,用户选择一个商品编号,
就把对应的商品添加到购物车里,最终用户输入q退出时,打印购买的商品列表。
products = [["iphone",6888],["MacPro",14800],["小米6",2499],["Coffee",31],["Book",60],["Nike",699]]
print("-"*5,"商品列表","-"*5)
for i in range(6):
print(i,products[i][0],products[i][1])
shopping_cart = []
while True:
product_id = input("输入你想购买的商品id:")
if product_id == "q":
break
else:
shopping_cart.append(product_id)
for i in shopping_cart:
print(int(i),products[int(i)][0],products[int(i)][1])