【问题描述】从键盘输入一个字符串,分别统计数字,字母(包括大小写)和其他字符的个数,输出每个字符及其个数。要求:输出用字典:{'字母':n1,'数字':n2,'其他':n3},提示:字母统计方法isalpha(),数字统计方法isdigit()。
【样例输入】12345 *dfdg
【样例输出】{'数字': 5, '其他': 2, '字母': 4}
a = input()
b = len(a)
word = []
tab = []
math = []
other = []
for i in range(0, b):
l = a[i].isalpha() # 字母
m = a[i].isdigit() # 数字
n = a[i].isspace() # 空格
if l == True:
word.append(a[i])
else:
if m == True:
math.append(a[i])
else:
if n == True:
tab.append(a[i])
else:
other.append(a[i])
v={'数字':0,'其他':0,'字母':0}
v['数字']=len(math)
v['字母']=len(word)
v['其他']=b-len(math)-len(word)
print(v)