Commit 7e1aeb4c by BellCodeEditor

auto save

parent d6cd5b97
Showing with 24 additions and 0 deletions
open函数的格式
文件名=open(r‘地址’,‘模式’,encoding="编码"
例子:f=open(r"C:\Users\Lenovo\Desktop\老师.txt",'w',encoding="utf-8")
f.write('石头0本')
#使用with关键词打开文件,只读模式
#使用for遍历文件
#判断“小郭10本”在不在文件中
#如果在文件中就打印(存在)
\ No newline at end of file
with open(r"C:\Users\Lenovo\Desktop\晓芹.txt","r",encoding="utf-8") as f:
a=f.readlines()
list=[]
for i in a:
q=i.split()
sum=0
for he in q[1:]:
sum=sum+int(he)
zuhe=q[0]+str(sum)+'\n'
list.append(zuhe)
with open(r"C:\Users\Lenovo\Desktop\晓芹.txt","a",encoding="utf-8") as f:
f.writelines(list)
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