【问题描述】从键盘输入字符串,统计其中大写字母的、小写字母、数字以及其他字符的个数。(字符串)
【输入形式】含有大写字母、数字等其他字符的字符串
【输出形式】统计的个数
【样例输入】 There are3dogs, But ALICE can not find them.
【样例输出】7
27
1
11

从键盘输入字符串,统计字符个数
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- Fioman_Hammer 2021-11-02 17:56关注
data = input("请输入字符串") upperCount = 0 lowerCount = 0 digitCount = 0 otherCount = 0 for c in data: if c.isupper(): upperCount += 1 elif c.islower(): lowerCount += 1 elif c.isdigit(): digitCount += 1 else: otherCount += 1 print(upperCount) print(lowerCount) print(digitCount) print(otherCount)
结果:
如果觉得答案对你有帮助,请点击下采纳,谢谢~
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报