Commit ee16e68a by BellCodeEditor

save project

parent 49121790
Showing with 7 additions and 11 deletions
fileq = open(r"C:\Users\Windows 10\Desktop\新建文本文档.txt","w",encoding="utf-8")
fileq.write("小兰:12本")
fileq.write("小红:12本")
fileq.write("小包:12本")
fileq.write("小梅:12本")
fileq.close()
\ No newline at end of file
with open(r"C:\Users\Windows 10\Desktop\book.txt",'w',encoding='utf-8')as a:
a.write("小兰:12本\n小强:10本\n小明:8本\n小红:9本")
new_a=''
with open(r"C:\Users\Windows 10\Desktop\book.txt",'r',encoding='utf-8')as a:
for i in a:
if "小强:10本" in i:
i=i.replace("小强:10本","小强:11本")
new_a+=i
with open(r"C:\Users\Windows 10\Desktop\book.txt",'w',encoding='utf-8')as a:
a.write(new_a)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment