我正在学习Python课程,但在使用while循环时遇到了问题。我的代码旨在检查密码是否具有最小长度=6和最大长度=14,并且还将检查密码是否仅包含数字或字母。如果它既包含数字又包含字母,则应打印“强密码”,如果它只包含数字或字母,则应打印“弱密码”。
当我运行我的代码时,出现错误信息:'name password_length is not defined'。我不确定该怎么办?我的代码是否正确?我是否应该将password_length放在while循环外面?
MIN_PASSWORD_LENGTH = 6
MAX_PASSWORD_LENGTH = 14
while password_length >= MIN_PASSWORD_LENGTH or password_length <= MAX_PASSWORD_LENGTH:
password_length = len(password)
password = input("Enter your password: ")
if password.isalpha():
print("Your password is weak!")
elif password.isnumeric():
print("Your password is weak!")
else:
print("Your password is strong!")
print("Number of characters used in password: ", password_length,"the min length expected is: ",MIN_PASSWORD_LENGTH,
"the max length is: ", MAX_PASSWORD_LENGTH)
当我运行我的代码时,出现错误信息:'name password_length is not defined'。我不确定该怎么办?我的代码是否正确?我是否应该将password_length放在while循环外面?