输入Python3.7 is very good!
输出
字母16个
数字2个
空格3个
其他字符2个
用 Python 内置函数来实现这个功能:
string = "Python3.7 is very good!"
letter_count = 0
digit_count = 0
space_count = 0
other_count = 0
for char in string:
if char.isalpha():
letter_count += 1
elif char.isdigit():
digit_count += 1
elif char.isspace():
space_count += 1
else:
other_count += 1
print(f"字母{letter_count}个")
print(f"数字{digit_count}个")
print(f"空格{space_count}个")
print(f"其他字符{other_count}个")