Python 循环:要求创建一个密码检查的代码,先检查长度,正确后再检查强度

Python 循环:要求创建一个密码检查的代码,首先要计算输入代码的长度,必须满足6-8,否则提示需要重新输入直到满足长度;密码满足长度后,再检查的密码的强度,如果只包含数字则显示弱,只包含字母显示弱,其他则显示强,并输出密码长度
问题如上,遇到的问题:密码在第一个while循环后不能进入第二个循环,也就是长度符合后不能检测强弱

MIN_PASSWORD_LENGTH = 6
MAX_PASSWORD_LENGTH = 8

password = input("Enter your password:")
password_length = len(password)

while not 6 <= password_length <= 8:
print("Invalid-password_length must between 6 and 8")
input("Enter your password:")
while 6 <= password_length <= 8:
if password.isalpha():
print("password weak - only contains letters")
elif password.isdigit():
print("password weak - only contains numbers")
else:
print("password strong")

print("the length of the password is:{}".format(password_length))

while 改成 if


MIN_PASSWORD_LENGTH = 6
MAX_PASSWORD_LENGTH = 8

password = input("Enter your password:")
password_length = len(password)

if not 6 <= password_length <= 8:
    print("Invalid-password_length must between 6 and 8")
    input("Enter your password:")
else:
    if password.isalpha():
        print("password weak - only contains letters")
    elif password.isdigit():
        print("password weak - only contains numbers")
    else:
        print("password strong")

print("the length of the password is:{}".format(password_length))