现有商品列表如下:
products = [[“iphone”,6888],[“MacPro”,14800],[“小米6”,2499],
[“Coffee”,311],[“Book”,60],[“Nike”,699]],需打印出以下格式:
#本人使用较为麻烦的方式写出结果。会多多借鉴其他优秀的解答。
products = [["iphone",6888],["MacPro",14800],["小米6",2499],
["Coffee",311],["Book",60],["Nike",699]]
i = 0
n = 5
print("-----商品列表-----")
for product in products:
if i <= n:
print(i,product[0],product[1],end="\n")
i += 1
#结果如下: