# import re
fname = '作业一素材.txt'
with open(fname, 'r',encoding='utf-8') as f:
lines = f.readlines()
last_line = lines[-3]
goal=last_line.split(" ")
word=goal[-1]
goal = re.split(r'[.]', word)
word = goal[0]
print("所求结果为",len(word))
先导入正则表达式模块,然后导入作业一素材文件并读取,按行读取文件提取最后一行, 用空格将该行文字分割成以单词为单位,读取最后一个单词,并去掉最后的符号,用长度函数计算长度