李祉琳的作业一

代码


  import re

  t = open('作业一素材.txt', mode='r', encoding='utf-8')
  txt = t.read()
  x=re.split("\n", txt)
  line = x[-3]
  words = re.split("\s", line)
  word = words[-1][:-1]

  print("最后一个单词",word,"的长度是",len(word))

结果

结果截图

附加题代码


  import re

  t = open('附加题素材.txt', mode='r', encoding='utf-8')
  txt = t.read()
  x = re.split("。", txt)
  s = x[6]
  n = re.split(",", s)
  print("最后一个句子为:",n[-1],"它的长度是",len(n[-1]))

结果

结果截图

解释(步骤)