Commit a50b0da1 by BellCodeEditor

save project

parent 085fd23b
Showing with 10 additions and 6 deletions
# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' # 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本'
fill=open('C:\\Users\\yu\\Desktop\\编程\\tt.txt','w',encoding='gb2312') fill=open('C:\\Users\\yu\\Desktop\\编程\\tt.txt','w',encoding='gb2312')
fill.write("小兰:12\n") fill.write("小兰:11\n")
fill.write("小丽:11本\n") fill.write("小丽:11本\n")
fill.write("李文:9本\n") fill.write("李文:9本\n")
fill.write("张伟:16本\n") fill.write("张伟:16本\n")
...@@ -9,8 +9,12 @@ fill.close() ...@@ -9,8 +9,12 @@ fill.close()
#with open('C:\\Users\\yu\\Desktop\\编程\\tt.txt','a',encoding='gb2312') as fill: #with open('C:\\Users\\yu\\Desktop\\编程\\tt.txt','a',encoding='gb2312') as fill:
#fill.write("小红:999999本\n") #fill.write("小红:999999本\n")
new_1=''
with open('C:\\Users\\yu\Desktop\\编程\\tt.txt','r',encoding='gb2312') as fill: with open('C:\\Users\\yu\Desktop\\编程\\tt.txt','r',encoding='gb2312') as fill:
a=fill.read() for data in fill:
for i in a: if '小兰:11本' in data:
if '小兰:12本' in i: new_1=data.replace('小兰:11本','小兰:9999999999999999999999999999本')
new_1=new_1+data
\ No newline at end of file with open('C:\\Users\\yu\Desktop\\编程\\tt.txt','w',encoding='gb2312') as fill:
fill.write(new_1)
print(new_1)
\ 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