统计字母数字和特殊字符的个数
源程序:
print("请输入一串字符(包含大小写字母、数字和其他字符):")
str1 = input()
upp_num = 0
low_num = 0
digit = 0
other = 0
for i in str1:
if "a" <= i <= "z":
low_num += 1
elif "A" <= i <= "Z":
upp_num += 1
elif "0" <= i <= "9":
digit += 1
else:
other += 1
print("小写字母 :", low_num, " 个。", "\n大写字母:", upp_num, " 个。")
print("\n数字 :", digit, " 个。", "\n其他字符:", other, " 个。")