这是我的代码。我无法弄清楚如何使我的程序计数非字母数字。我是一名新的编码学生,所以请放轻松。
infile = open("Gettysburg.txt", "r")
data = infile.readlines()
non_alpha_num = 0
uppercase_count = 0
lowercase_count = 0
whitespace_count = 0
digit_count = 0
for character in data:
if character.isupper():
uppercase_count += 1
elif character.islower():
lowercase_count += 1
elif character.isspace():
whitespace_count +=1
elif character.isdigit():
digit_count +=1
if not character.isalnum() and not character.isspace():
non_alpha_num += 1
print("Jake's text document counter")
print('The uppercase count is ', uppercase_count)
print('The lowercase count is ', lowercase_count)
print('The digit count is ', digit_count)
print('The whitespace count is ', whitespace_count)
print('The non alphanumeric count is ', non_alpha_num)