华为机试HJ40统计字符
题目:
想法:
统计上述题目中的四种字符的个数存入字典中,按指定顺序进行输出
input_str = input()
str_dict = {"alpha": 0, "space": 0, "number": 0, "others": 0}
for i in input_str:
if i.isalpha():
str_dict["alpha"] += 1
elif i == " ":
str_dict["space"] += 1
elif i.isdigit():
str_dict["number"] += 1
else:
str_dict["others"] += 1
print(str_dict["alpha"])
print(str_dict["space"])
print(str_dict["number"])
print(str_dict["others"])