周浪的作业一

代码


f = open('作业一.txt',encoding='utf-8')
txt = f.read()
f.close()

index = txt.find('\n顺丰')

txt_target = txt[:index]
lines = txt_target.split('\n')
last_line = lines[-1]
words = last_line.split(' ')
last_word = words[-1]

for i in range(1,len(last_word)):
    last_character = last_word[-i]
    if last_character.isalpha():
        last_word = last_word[:-i+1]
        break

if i == len(last_word):
    last_word = words[-2]

print(last_word)
a=len(last_word)
print(a)

结果

结果截图

解释

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