龚汝何的作业一

代码


# replace with your code here
with open('a.txt', encoding='utf-8') as file:
    content = file.readlines()
    data_line = content[-2]
    data_char = ''
    char_num = -1
    count = 0
    while data_char != ' ':
        data_char = data_line[char_num]
        if ('a' <= data_char <= 'z') or ('A' <= data_char <= 'Z'):
            count = count + 1
        else:
            pass
        char_num = char_num - 1
print(count)

结果

结果截图

解释

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