我正在尝试制作一个密码强度模拟器,它要求用户输入密码,然后返回分数。
我在用:
islanum()
isdigit()
isupper()
尝试看看输入的密码有多好。
我不想返回布尔值,而是希望它评估密码的每个字符,然后程序将所有“True”值相加并将其转换为分数。示例代码:
def upper_case():
points = int(0)
limit = 3
for each in pword:
if each.isupper():
points = points + 1
return points
else:
return 0
任何帮助将非常感激!!谢谢!!
.isalnum()
, .isupper()
, .isdigit()
和朋友的方法str
在 Python 中输入并这样调用:
>>> s = "aBc123"
>>> s[0].isalnum()
True
>>> s[1].isupper()
True
>>> s[3].isdigit()
True
Simple getscore()
功能:
s = "aBc123@!xY"
def getscore(s):
score = 0
for c in s:
if c.isupper():
score += 2
elif c.isdigit():
score += 2
elif c.isalpha():
score += 1
else:
score += 3
return score
print getscore(s)
Output:
13
更好的版本:
s = "aBc123@!xY"
def getscore(s):
return len(s) + len([c for c in s if c.isdigit() or c.isupper() or not c.isalpha()])
print getscore(s)
Output:
17
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)