Commit 30ad5995 by BellCodeEditor

save project

parent 9edfc8e1
Showing with 14 additions and 5 deletions
......@@ -3,12 +3,21 @@
# file.write('小兰:12本\n小丽:11本\n李文:9本\n张伟:16本')
# file.close()
# with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','a',encoding='utf-8') as file:
# file.write('小强:12本\n李明:15本')
with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','a',encoding='utf-8') as file:
file.write('小强:12本\n李明:15本')
n_data=''
with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','r',encoding='utf-8') as file:
for data in file:
if '小强:10本' in data:
print('小强在里面!')
data=data.replace('小强:10本','李明:11本')
if '小兰:12本' in data:
print('小兰在里面!')
\ No newline at end of file
data=data.replace('小兰:12本','李明:11本')
n_data+=data
with open(r'C:\Users\Makcoo-Bellcode\Desktop\book.txt','w',encoding='utf-8') as file:
file.write(n_data)
with open(r'C:\Users\Makcoo-Bellcode\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