-*- 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 = ‘‘‘ ==============输入字符串信息:%s================= 大写字母出现了 %d次 小写字母出现了 %d次 数字出现了 %d次 其它字符出现了 %d次 ============================================== ‘‘‘ print(message %(content,upper_str_count,lower_str_count,num_count,other_count))
原文:https://www.cnblogs.com/python-cat/p/12131751.html