Python 检查密码的强度

Python 检查密码的强度,python,passwords,Python,Passwords,我不是在找人给我答案。 我只是想寻求一点帮助来解释为什么这不起作用。 这与其他可用的密码强度问题也略有不同 def password(pwd): if len(pwd) >= 10: is_num = False is_low = False is_up = False for ch in pwd: if ch.isdigit():

我不是在找人给我答案。 我只是想寻求一点帮助来解释为什么这不起作用。 这与其他可用的密码强度问题也略有不同

def password(pwd):
        if len(pwd) >= 10:
            is_num = False
            is_low = False
            is_up = False
            for ch in pwd:
                if ch.isdigit():
                    is_num = True
                if ch.islower():
                    is_low = True
                if ch.isupper():
                    is_up = True

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert password(u'A1213pokl') == False, "1st example"
    assert password(u'bAse730onE4') == True, "2nd example"
    assert password(u'asasasasasasasaas') == False, "3rd example"
    assert password(u'QWERTYqwerty') == False, "4th example"
    assert password(u'123456123456') == False, "5th example"
    assert password(u'QwErTy911poqqqq') == True, "6th example"

您缺少2条返回语句来完成此操作:

def password(pwd):
    if len(pwd) >= 10:
        is_num = False
        is_low = False
        is_up = False
        for ch in pwd:
            if ch.isdigit():
                is_num = True
            if ch.islower():
                is_low = True
            if ch.isupper():
                is_up = True
        return is_num and is_low and is_up
    return False

你的问题是什么?你的密码函数不会返回任何东西。它将始终返回None。您还没有说明您实际希望函数执行的操作。您检查了返回值,但没有返回值。请描述函数调用的预期结果。我一直将return True放在最后一个if语句下,而不是return is_num and is_low and is_up。然后,我没有在if条件语句的开头返回False。这个问题已经解决了,我非常感谢这个帖子给我的支持。谢谢大家有人能解释一下为什么投票被否决吗?我想多了解一下这个名声。我已经读过了,但是我创建这个线程的方式,我试图理解为什么它被否决了。我看到一些人说他们没有看到我问的问题,但问题在标题中。我只是想寻求一点帮助来解释为什么这不起作用哦,哇!谢谢你,伙计!这简直让我神魂颠倒!如果这个或任何答案解决了你的问题,请通过点击复选标记来考虑。这向更广泛的社区表明,你已经找到了一个解决方案,并给回答者和你自己带来了一些声誉。但是没有义务这么做,这不是问题。我现在就去。我非常抱歉,因为这是我第一次真正使用stackoverflow,现在我将更频繁地使用它。非常感谢。三线性时间解?:通过字符串循环3次。比在一个循环中执行所有检查慢,即使可读性更强。三线性意味着三次线性。线性本身意味着完成所需的时间与列表中的元素数量成正比。不过,这是一个很好的解决方案,更具Python风格:
    def password(pwd):
        upper = any(ch.isupper() for ch in pwd)
        lower = any(ch.islower() for ch in pwd)
        is_dig = any(ch.isdigit() for ch in pwd)
        return  upper and lower and is_dig and len(pwd) > 10