Commit b8c65754 by BellCodeEditor

save project

parent dbdccff1
Showing with 13 additions and 12 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' new_data=""
# file1=open(r"C:\Users\Administrator\Desktop\book.txt","w",encoding="utf-8")
# file1.write("a:12本\n")
# file1.write("b:11本\n")
# file1.write("c:9本\n")
# file1.write("d:16本\n")
with open(r"C:\Users\Administrator\Desktop\book.txt","r",encoding="utf-8")as file: with open(r"C:\Users\Administrator\Desktop\book.txt","r",encoding="utf-8")as file:
for i in file: for data in file:
if "e:10本"in i: if "a,12本"in data:
print("在") data=data.replace("a,12本","a,13本")
if "f:12"in i: if "b,11本"in data:
print("在") data=data.replace("b,11本","b,12本")
\ No newline at end of file new_data+=data
with open(r"C:\Users\Administrator\Desktop\book.txt","w",encoding="utf-8")as file:
file.write(new_data)
with open(r"C:\Users\Administrator\Desktop\book.txt","r",encoding="utf-8")as file:
a=file.read()
print(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