12.输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

s="123 abc !@# ^&*"

digit_num=0

letter_num=0

space_num=0

other_num=0

for i in s:

    if i.isalpha():

        letter_num+=1

    elif i.isdigit():

        digit_num+=1

    elif i.isspace():

        space_num+=1

    else:

        other_num+=1

 

print u"共有字母:",letter_num

print u"共有数字:",digit_num

print u"共有空格:",space_num

猜你喜欢

转载自www.cnblogs.com/luo25236240/p/9255421.html