Python作业?

Python021

Python作业?,第1张

def main():

句子=原始输入('句子')

words = sentence.split()

临时= " "

对于范围内的idx(len(单词)):

temp = words[idx][0]。上部()

temp = words[idx][1:]

words[idx] = temp

临时= " "

返回“”。加入(单词)

就做一下标点符号的替换吧

txt = open("绝代风华.txt","r+",encoding='utf-8').read()#修改访问模式为"r+"

txt2=txt.replace(",",' ').replace("。",' ')#还有什么符号就自己加吧

txt3=open("E://绝代风华2.txt","w+",encoding='utf-8')#设置路径比较好,在文件名前加

txt3.write(txt2)#写入替换好的文本,形成新文本

#以下三句放在代码的后面

txt.close()

txt3.close()

#打开新文本,若查看的文本内容无误,这两行代码可以注释。

pl=open("E://绝代风华2.txt","r",encoding='utf-8').read()

pl.close()