题解 | 统计字符
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
s = input()
count1 = 0 # 空格个数
count2 = 0 # 字母个数
count3 = 0 # 数字个数
count4 = 0 # 其他字符个数
for i in s:
if ord(i) == 32:
count1 += 1
elif ord(i) >= 48 and ord(i) <= 57:
count3 += 1
elif ord(i) >= 65 and ord(i) <= 90 or ord(i) >= 97 and ord(i) <= 122:
count2 += 1
else:
count4 += 1
print(count2)
print(count1)
print(count3)
print(count4)
查看20道真题和解析