Commit 55206e0b by BellCodeEditor

save project

parent 9d41970c
Showing with 8 additions and 7 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
new = ''# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
file = open("C:\\Users\\wzj\\Desktop\\test.txt",'w',encoding ='utf-8')
file.write("小兰:12本\n小丽:11本\n李文:9本\n张伟:16本")
file.close()
with open("C:\\Users\\wzj\\Desktop\\test.txt",'r',encoding ='utf-8') as file:
a = file.read()
print(a)
if "小强:11本" in file:
print("T")
else:
print("F")
for data in file:
if "小丽" in data:
data = data.replace('小丽','小白')
new += data
print(new)
with open("C:\\Users\\wzj\\Desktop\\test.txt",'w',encoding ='utf-8') as file:
file.write(new)
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