题解 | #字符类型计数#

字符类型计数

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

X = input()
alpha, digit, space, other = 0, 0, 0, 0
for i in range(len(X)):
    a = ord(X[i])
    if a >= 65 and a <= 90:
        alpha += 1
    elif a >= 97 and a <= 122:
        alpha += 1
    elif a >= 48 and a <= 57:
        digit += 1
    elif a == 32:
        space += 1
    else:
        other += 1
print("alpha:", alpha)
print("digit:", digit)
print("space:", space)
print("other:", other)
全部评论

相关推荐

点赞 评论 收藏
分享
我也曾抱有希望:说的好直白
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务