购物车程序更新:
更新商家入口,实现以下功能:
1. 商家能够修改商品价格;
2. 商家能够下线商品;
3. 商家能够增加商品;
4. 商品信息存在文件中

1 # -*- coding:utf-8 -*- 2 # LC 3 product_list = [] 4 product_line = [] 5 count = 0 6 7 with open("product_list","r") as f: #打开商家货品清单文件 8 for item in f: 9 product_line = item.rstrip().split(",") #将每行赋值给成一个列表,以“,”区分 10 product_list.append(product_line) #将每行的列表加入product_list列表中 11 12 print("This is your production".center(50,"-")) #打印列表 13 for i in product_list: 14 print(count,i) 15 count+=1 16 17 #提供增加商品,修改商品价格,删除商品功能 18 while True: 19 select = input("Please input you selection,'a' to add,'m' to modified the price,'d' to Delete,'q' to quit :") 20 count = 0 21 if select == 'a': 22 add_product = input("Please input new product name:") 23 add_price = input("Please input new product price:") 24 new_product = [add_product,add_price] #将新添加的商品赋值成列表 25 product_list.append(new_product) #向产品清单列表中插入新添加的商品 26 with open("product_list","a") as f_add: #将添加的商品写入文件中,以追加的方式 27 f_add.writelines(product_list[-1][0]+","+product_list[-1][1]+" ") 28 print("