Commit 5117352b by BellCodeEditor

save project

parent ea4275c0
Showing with 11 additions and 4 deletions
...@@ -7,10 +7,17 @@ file.write('张伟:16本\n') ...@@ -7,10 +7,17 @@ file.write('张伟:16本\n')
file.close() file.close()
with open(r"C:\Users\Administrator\Desktop\book.txt",'a',encoding='utf-8') as file: with open(r"C:\Users\Administrator\Desktop\book.txt",'a',encoding='utf-8') as file:
file.write('小强:12本\n') file.write('小强:12本\n')
file.write('小明:15本\n') file.write('小明:15本\n')
new=""
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 i in file:
if '小强:12本\n' in i: if '小强:12本\n' in i:
print("小强捐了12本") print(1)
i.replace('小强:12本\n','小强:11本\n')
if '小兰:12本\n' in i: if '小兰:12本\n' in i:
print("小兰捐了12本") i.replace('小兰:12本\n','小兰:14本\n')
\ No newline at end of file print(1)
new=new+i
with open(r"C:\Users\Administrator\Desktop\book.txt",'w',encoding='utf-8') as file:
file.write(new)
\ 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