输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数,并输出统计结果。(搜索新知识)?

任意输入一行字符,并统计其中的英文字母,空格,数字,其他字符的个数、

import string

s = input('请输入字符串:\n')
# 初始化
letters = 0
space = 0
digit = 0
other = 0

i = 0
while i < len(s):
    c = s[i]
    i = i + 1
    # 当c.isalpha为真时,letters = letters + 1
    if c.isalpha(): 
        letters += 1    
    elif c.isspace():
        space += 1
    elif c.isdigit():
        digit += 1
    else:
        other += 1
print('char = %d, space = %d, digit = %d, other = %d' % (letters, space, digit, other))