题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

def A(s: str):
    if len(s) >= 8:
        return 1
    else:
        return 0


def B(s: str):
    tag1, tag2, tag3, tag4 = 0, 0, 0, 0
    for i in s:
        if i.isalpha() == True:
            if i.upper() == i:
                tag1 = 1
            if i.lower() == i:
                tag2 = 1
        elif i.isdigit() == True:
            tag3 = 1
        elif i != " ":
            tag4 = 1
    return tag1 + tag2 + tag3 + tag4 >= 3


def C(s: str):
    tag1 = 1
    for i in range(0, len(s) - 3):
        if s.count(s[i : i + 3]) >= 2:
            tag1 = 0
            break
    return tag1


s = input()
if A(s) * B(s) * C(s) == 1:
    print("OK")
else:
    print("NG")

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务