我不是在找人给我解决方案。 我只是寻求一些帮助,为什么这不起作用。 这也与其他可用的密码强度问题略有不同
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"
答案 0 :(得分:1)
你缺少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
答案 1 :(得分:1)
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