# coding: UTF-8
def count_test(st):
cap, small, num, other = 0, 0, 0, 0
for i in st:
if i.isupper():
cap = cap + 1
elif i.islower():
small = small + 1
elif i.isdigit():
num = num + 1
else:
other = other + 1
print('大写字母个数:%dn小写字母个数:%dn数字个数:%dn其他字符个数:%dn' % (cap, small, num, other))
string = input('输入字符串:')
count_test(string)
运行结果如下:
输入字符串:Hello123@#$
大写字母个数:1
小写字母个数:4
数字个数:3
其他字符个数:3