这个是要完成的内容
代码如下
print("-----------商品列表-------------")
products=[["iphone","6888"],["MacPro","14800"],["MI6","2499"],["Coffee","31"],["Book","60"],["Nike","699"]]
i=0
j=0
N=2
k=0
buy=[]
while i<6:
print("%-5d%-9s%s"%(i,products[i][0],products[i][1]))
i+=1
while j<N:
b=input("请选择一个商品编号,输入q退出")
j+=1
if b=="q":
continue
elif int(b)>=0 and int(b)<=5 :
buy.extend(products[int(b)])
else: #bug输入其他字母会报错
print("输入错误重新输入:")
j-=1
y=len(buy)
sum=0
print("——————————你购买的商品列表————————————\n")
while k<y:
print(" %-8s%-8s"%(buy[k],buy[k+1]))
sum+=int(buy[k+1])
k+=2
print(" 总价为%d"%sum)