题解 | #字符类型计数#

字符类型计数

http://www.nowcoder.com/practice/73ac4280bcfe4d64b85763e86e367e15

str = input()
count_alpha = 0
count_alnum = 0
count_space = 0
count_other = 0
for i in str:
    if(i.isalpha()):
        count_alpha += 1
    elif(i.isalnum()):
        count_alnum += 1
    elif(i.isspace()):
        count_space += 1
    else:
        count_other += 1
         
print(f"alpha: {count_alpha}")
print(f"digit: {count_alnum}")
print(f"space: {count_space}")
print(f"other: {count_other}")
         

全部评论

相关推荐

10-09 22:05
666 C++
找到工作就狠狠玩CSGO:报联合国演讲,报电子烟设计与制造
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务