用python代码输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的

用python代码输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的

line=raw_input()
alpha=space=digit=other=0
for c in line:
    if c.isalpha() :
        alpha+=1
    elif c.isspace():
        space+=1
    elif c.isdigit():
        digit+=1
    else:
        other+=1
print("""The alpha characters:%d
The space characters:%d
The digit characters:%d
The other characters:%d"""%(alpha,space,digit,other))

温馨提示:答案为网友推荐,仅供参考
相似回答