题解 | #字符类型计数#
字符类型计数
http://www.nowcoder.com/practice/73ac4280bcfe4d64b85763e86e367e15
str = input()
count_alpha = 0
count_alnum = 0
count_space = 0
count_other = 0
for i in str:
if(i.isalpha()):
count_alpha += 1
elif(i.isalnum()):
count_alnum += 1
elif(i.isspace()):
count_space += 1
else:
count_other += 1
print(f"alpha: {count_alpha}")
print(f"digit: {count_alnum}")
print(f"space: {count_space}")
print(f"other: {count_other}")
count_alpha = 0
count_alnum = 0
count_space = 0
count_other = 0
for i in str:
if(i.isalpha()):
count_alpha += 1
elif(i.isalnum()):
count_alnum += 1
elif(i.isspace()):
count_space += 1
else:
count_other += 1
print(f"alpha: {count_alpha}")
print(f"digit: {count_alnum}")
print(f"space: {count_space}")
print(f"other: {count_other}")