【问题描述】输入一串字符,统计其中英文字符、空格、数字和其他字符的个数。(isalpha() 、 isspace () 、isdigit())

【输入形式】input输入一串字符
【输出形式】
【样例输入】

fg34c  4#$gh

【样例输出】

5 2 3 2

【样例说明】
【评分标准】

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])

print(len(word),len(tab),len(math),len(other))

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐