Search code examples
pythoninfinite-loop

Why isn't my code exiting the infinite loop? (python)


I am very new to Python. I was creating a program to begin work on something big that I believe would be revolutionary. When I saved my code and tested it, however, it remained in the infinite loop I had created even after I typed something that did not match the conditions! Could I please get some help?

Code:

*...snip...* print("You may now choose a password. Your password must: \n"
      + "-be at least 8 characters \n"
      + "-NOT be 'password' \n"
      + "-NOT be an ordered list of numbers \n")
print("What is your password?")
password = input()
if password == "password" or "Password" or "PASSWORD" or "12345678":
    while password == "password" or "Password" or "PASSWORD" or "12345678":
        print("That password is too weak. Choose another password.")
        password = input()
else: *...snip...*

Solution

  • You have to write

    if password == "password" or password == "Password" or password == "PASSWORD" or password == "12345678":
    

    Your if evaluates your statement like this : if password is equal to the string "password" or if the string "Password" is different from null and so on.