#购物 products = [['小米',1600],['苹果',3000],['华为',1500],['oppo',1000],['vivo',1000]] print("--------商品列表--------") j = 0 index = 0 shops = [] money = [] x = [0,1,2,3,4] for i in products: print(' %d %s %d'%(j,i[0],i[1])) j += 1 while True: z = input('您需要什么:') if z.isdigit(): z = int(z) if (z in x): shops.append(products[z]) money.append(products[z][1]) else : print('输入有误!') break elif(z == 'p'): g = 0 sum = 0 print("-------购物车-----------") for shop in shops: g += 1 for i in shop: print(i,end='\t') print('\n') for mon in money: sum += mon