华为机试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"])
相关推荐
熊猫钓鱼>_>21 小时前
从零到一:使用 ArkTS 构建你的第一个鸿蒙应用
华为·移动开发·harmonyos·arkts·鸿蒙·component·网页开发
lqj_本人1 天前
鸿蒙原生API与OnsenUI组件的双向通信实现
华为·harmonyos
爱笑的眼睛111 天前
深入理解ArkTS类的继承与多态:构建灵活可扩展的HarmonyOS应用
华为·harmonyos
爱笑的眼睛111 天前
HarmonyOS Toggle开关组件的深度状态管理实践
华为·harmonyos
Kisang.1 天前
【HarmonyOS】ArkWeb——从入门到入土
前端·华为·typescript·harmonyos·鸿蒙
A-刘晨阳1 天前
《华为数据之道》发行五周年暨《数据空间探索与实践》新书发布会召开,共探AI时代数据治理新路径
人工智能·华为
大咖分享课1 天前
HarmonyOS 6 有哪些新变化、新功能?
华为·harmonyos
EterNity_TiMe_1 天前
autoconf 工具 OpenHarmony PC 适配指南
华为·harmonyos
爱笑的眼睛111 天前
深入HarmonyOS USB设备管理:从基础到高级开发
华为·harmonyos
ifeng09181 天前
HarmonyOS远程真机调试实战:云测与设备管控技巧
华为·harmonyos