华为机试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"])
相关推荐
lqj_本人44 分钟前
鸿蒙OS&UniApp 实现自定义的侧边栏菜单组件#三方框架 #Uniapp
华为·uni-app·harmonyos
Vence08152 小时前
Flutter3.22适配运行鸿蒙系统问题记录
flutter·华为·harmonyos·鸿蒙
郑知鱼5 小时前
【拥抱鸿蒙】Flutter+Cursor轻松打造HarmonyOS应用(二)
flutter·华为·harmonyos·鸿蒙·cursor·移动端·鸿蒙next·ohos
xmweisi027 小时前
【华为战报】4月、5月 HCIP考试战报!
华为
zero_orez61 天前
折半搜索【2024华为智联杯 K.时光】
算法·华为·深度优先
Junzeng_Kai1 天前
网络:华为S5720-52X-SI交换机重置console密码
网络·华为
lqj_本人1 天前
鸿蒙OS&UniApp 制作美观的文章列表展示组件#三方框架 #Uniapp
华为·uni-app·harmonyos
郑知鱼1 天前
【拥抱鸿蒙】Flutter+Cursor轻松打造HarmonyOS应用(一)
flutter·华为·harmonyos·鸿蒙·cursor·移动端·鸿蒙next·ohos
Bruce_Liuxiaowei1 天前
HarmonyOS NEXT~鸿蒙系统运维:全面解析与最佳实践
华为·harmonyos
lqj_本人1 天前
鸿蒙OS&UniApp 制作个性化的评分星级组件#三方框架 #Uniapp
华为·uni-app·harmonyos