所以我是python的初学者,我一辈子都想不通为什么它不会检查并添加每个字母
def howstrong (password):
points = len(password)
charactersallowed = ["!", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+"]
for ch in password:
if ch.isupper():
points= points+5
elif ch.islower():
points = points+5
elif ch.isdigit():
points = points+5
elif ch in charactersallowed:
points= points+5
else:
points = points+0
return points
如果我输入密码密码!在我的代码中,它告诉我我的积分是 14,但对于这个密码,它应该是 24?下面我将添加我的其余代码,但我怀疑它在那部分,我相信我的 for 循环中的某个地方有错误。
def checkingmain():
while 1:
p = input("\nEnter password: ")
if len(p) < 8 or len(p) > 24:
print("Password must be 6 to 12 characters.")
elif input("Re-enter password: ") != p:
print("Passwords did not match. Please try again.")
else:
score= howstrong(p)
if not score:
print("Invalid character detected. Please try again.")
else:
if score <= 0:
print("your password is weak",score)
elif score>0 and score<20:
print("your password is medium",score)
else:
print("your password is strong",score)
break
如果有人能为有点python的初学者提供一个可以理解的解决方案,我将不胜感激。