统计各类字符个数题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
s = input('please input a string: ')
I_alpha = 0
I_space = 0
I_digit = 0
I_others = 0
for i in s:
if i.isalpha():
I_alpha += 1
elif i.isspace():
I_space += 1
elif i.isdigit():
I_digit += 1
else:
I_others += 1
print('char=' + str(I_alpha) +
'\nspace =' + str(I_space)+
'\ndigit=' + str(I_digit)+
'\nothers' + str(I_others))