python每日一练:输入一个字符串,统计其中的小写字母,大写字母,空格键,以及其它字符,并在一行内输出统计的个数

a = str(input())
smallword = 0
bigword = 0
number = 0
blank = 0
others = 0
longth = len(a) #记录字符串的长度,后面用于遍历次数

#i作为字符串中的具体字符参加遍历
for i in a:
    #若i在‘abcdefghijklmnopqrstuvwxyz’里面则小写字母加1
    if i in 'abcdefghijklmnopqrstuvwxyz' :
        smallword = smallword + 1
    if i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' :
        bigword = bigword + 1
    if i in ' ':
        blank = blank + 1
others = longth - smallword -bigword - blank
print(' 小写字母 :',smallword,' 大写字母 :',bigword,' 空格键 :',blank,' 其它字符: ',others)

python每日一练:输入一个字符串,统计其中的小写字母,大写字母,空格键,以及其它字符,并在一行内输出统计的个数_第1张图片

你可能感兴趣的:(python)