华为机试HJ40统计字符

华为机试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"])
相关推荐
0***R5152 小时前
HarmonyOS在智能车载中的车载系统
华为·车载系统·harmonyos
F***c3252 小时前
HarmonyOS在智能车载系统中的应用实践
华为·车载系统·harmonyos
D***t1315 小时前
HarmonyOS在智能家居中的华为生态
华为·智能家居·harmonyos
b***74885 小时前
HarmonyOS在智能家居中的语音助手
华为·智能家居·harmonyos
u***j3246 小时前
HarmonyOS分布式能力核心技术深度解析
分布式·华为·harmonyos
7***n756 小时前
HarmonyOS分布式数据管理
分布式·华为·harmonyos
S***y3967 小时前
HarmonyOS在智能家居中的情景模式
华为·智能家居·harmonyos
6***37947 小时前
HarmonyOS在智能家居中的场景联动
华为·智能家居·harmonyos
u***u6858 小时前
HarmonyOS在智能手表中的开发
华为·harmonyos·智能手表
0***149 小时前
HarmonyOS系统安全机制
华为·harmonyos