XXX的作业一

代码


import re

su_cai = open('作业一素材.txt', encoding='utf-8')
txt = su_cai.read()
su_cai.close()
# 打开文本,读取文本,关闭文本

txt1 = re.split('\n', txt)
# 用换行符分割句子
txt2 = txt1[-3]
# 提取最后一行
word1 = re.findall(r'(\w{1,})', txt2)
# 将标点符号去除
word = re.split(' ', txt2)
# 用空格分离出来
len(word1[-1])
# 输出单词长度

结果

结果截图

解释

如果所写代码复杂,且没有良好的注释,那么请在这里补充解释。