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

posted @ 2018-07-02 19:31  生活就是一种修行者  阅读(267)  评论(0编辑  收藏  举报