老男孩python学习第三天作业

问题一:输⼊⼀个字符串,要求判断在这个字符串中⼤写字⺟,⼩写字⺟,数字, 其它字符共出现了多少次,并输出

#!/user/bin/env python
# -*- coding:utf-8 -*-
content = input('请输入一个字符串:')
index = 0
content_len = len(content)
num_count = 0
upper_str_count = 0
lower_str_count = 0
other_count = 0
while True:
    if index >= content_len:
        break
    else:
        val = content[index]
        if val.isdigit():
            num_count += 1
        elif val.isupper():
            upper_str_count += 1
        elif val.islower():
            lower_str_count += 1
        else:
            other_count += 1
    index += 1
message = '''
===============输入字符串信息===============
            ⼤写字⺟出现了 %d次
            ⼩写字⺟出现了 %d次
                数字出现了 %d次
            其它字符出现了 %d次
============================================
'''
print(message % (upper_str_count, lower_str_count, num_count, other_count))

posted on 2019-09-25 16:11  傲慢小羽  阅读(277)  评论(0编辑  收藏  举报

导航