python自学第二周购物车
import fileinput #!/usr/bin/env pthon #!/usr/bin/env python # -*-coding:UTF-8-*- import os import sys def shop(): f=open("E:/product_list.txt",'r+') product=f.readlines() print(product) f.close() sf=open("E:/shop_list.txt",'r') shop=sf.readlines() sf.close() allproduct=[] allprice=[] product4=[] price4=[] for i in range(0,len(product)): product2=product[i].split() product3=product2[0] price=product2[1] allproduct.append(product3) allprice.append(price) yonghuleib=input('商家or用户:') while 1: if yonghuleib=='1': isinsert=input('你想干什么:') if isinsert=='2': productinsert=input('请输入增加商品的名称:') priceinsert=input('请输入增加商品的价格:') product4.append(productinsert) price4.append(priceinsert) pf=open("E:/product_list.txt",'a') product5=pf.write(product4[0]+' '+price4[0]+'\n') pf.close() if isinsert=='3': productupdate=input('请输入需要修改的商品名称:') priceupdate=input('请输入修改后商品价格:') if priceupdate.isdigit(): priceupdate=int(priceupdate) if productupdate in allproduct: with open("E:/product_list.txt",'r') as f: with open("E:/product_list.txt",'w') as f2: for line in f.readlines(): if productupdate in line: allprice[allproduct.index(productupdate)]=priceupdate f2.write(str(allprice))