python统计数字,大写字母,小写字母,空格个数

时间:2025-03-15 18:03:25

s=input()
num,Bchar,Schar,space,other = 0,0,0,0,0
for i in s:
if ():
num+=1
elif ():
Bchar+=1
elif ():
Schar+=1
elif ():
space+=1
else:
other+=1
print(f’大写字母个数{Bchar}、小写字母个数: {Schar}、数字个数: {num}、空格个数: {space}、其他字符个数: {other}')

s=input()
num,Bchar,Schar,space,other = 0,0,0,0,0
for i in s:
    if i.isdigit():
        num+=1
    elif i.isupper():
        Bchar+=1
    elif i.islower():
        Schar+=1
    elif i.isspace():
        space+=1
    else:
        other+=1
print(f'大写字母个数{Bchar}、小写字母个数: {Schar}、数字个数: {num}、空格个数: {space}、其他字符个数: {other}')