小破站看的教程 IT私塾 跟着做练习
products = [["iphone",6888],["MacPro",14800],["小米6",2499],["Coffee",31],["Book",60],["Nike",699]]
shop_car = []
print("------ 商品列表 ------")
i = 0
count = 0
for product in products:
print(i,product[0],product[1])
i+=1
while 1:
store = input("输入商品编号,添加对应商品到购物车 ")
if store == 'q':
break
elif int(store) >= 0 and int(store) <= 5:
shop_car.append(products[int(store)])
#print(products[int(store)])
count+=1
else:
print("无对应商品")
i = 0
for shop in shop_car:
print(i,shop[0],shop[1])
i+=1
中间变量没新建 都是直接操作参数 所以看上去不是很好 这里要区分好append 跟 extend 的用法 list整个添加是用append