0 python for-loop password-checker
所以我是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
Run Code Online (Sandbox Code Playgroud)
如果输入密码密码!在我的代码中它告诉我我的积分是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
Run Code Online (Sandbox Code Playgroud)
我很感激,如果有人能用一个有点蟒蛇初学者的可理解的解决方案回复我.