从键盘输入一个字符串,分别统计数字、字母(包括大小写)和其他字符的个数,并输出每类字符及其个数。
要求输出用字典形式:{'字母': n1,'数字': n2,'其他':n3}
( 提示:字母统计方法 isalpha(),数字统计方法 isdigit() )
输入样例:python is good
输出样例:{'数字': 0, '其他': 2, '字母': 12}
string = input("请输入一个字符串:")
count = {'数字': 0, '字母': 0, '其他': 0}
for char in string:
if char.isdigit():
count['数字'] += 1
elif char.isalpha():
count['字母'] += 1
else:
count['其他'] += 1
print(count)