products = [["iphone", 6888], ["MacPro", 14800], ["小米6", 2499], ["COffer", 31], ["Book", 60], ["Nike", 699]] shoping = [] print("----- 商品列表 -----") i = 0 for product in products: i += 1 print(i, end="\t") for name in product: print(name, end="\t") print("\n", end="") product.insert(0, i) # print(product) # print(product[0]) while True: s = input("你好,请选择你想购买的商品:") if not s.isdigit(): print("输入有误。") continue if 0 > int(s) > len(products): print("输入有误,没有该商品") continue shoping.append(s) bool1 = input("你还有需要购买的商品吗?y/n") if bool1 == 'Y' or bool1 == "y": continue elif bool1 == 'N' or bool1 == 'n': input1 = input("请输入q退出:") if input1 == 'q': break else: flag = False while True: input2 = input("你输入的不正确,请重新输入。q退出,如果还需要继续购买,请按任意键。。") if input2 == 'q': flag = True break else: break if flag: break else: continue else: flag1 = False while True: input3 = input("你输入的不正确,请重新输入。q退出,如果还需要继续购买,请按任意键。。") if input3 == 'q': flag1 = True break else: break if flag1: break else: continue if len(shoping) == 0: print("你的购物车为空") else: print("你好你购物车的商品有:") for k in shoping: k = int(k) for product1 in products: for name in product1: if product1[0] == k: print(name, end="\t") print("\n")
12-02
664
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-10
460
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-08
384
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)