Some guy
Some guy

Reputation: 11

why isn't this loop stopping?

while True:
    password=input("Enter a password. Make sure it:\nContains at least 1 capital letter\nContains at least 6 letters\n")
    time.sleep(0.35)
    if len(password)>5 and password.islower=="False":
        break

how do you make this stop. I want it to stop if it has one capital letter and is longer than 6 characters.

Upvotes: 1

Views: 86

Answers (3)

AGN Gazer
AGN Gazer

Reputation: 8378

Because islower is not a property but rather it is a function. Try this instead:

not password.islower()

In addition, as mentioned by @Dan, you compare the result of the islower() function (a boolean) with a string "False". In Python a boolean result can be used directly as shown above without comparing it to a string "False" (this is wrong) or to a boolean False (which is weird and dangerous). islower()==False would be True if password contains upper case characters.

Upvotes: -1

bruno desthuilliers
bruno desthuilliers

Reputation: 77902

Here :

password.islower=="False"

First, you're not calling the method - you need to add parens - so you compare a method with a string. It will never be true...

Then, once you fix this:

password.islower() == "False"

you end up comparing a boolean with a string. It will never be true either, you want to compare with the boolean False (no quotes):

password.islower() == False

As a last note, this is usually spelled:

not passsword.islower()

Upvotes: 5

mrCarnivore
mrCarnivore

Reputation: 5068

if len(password)>5 and not password.islower():

or

if len(password)>5 and password.islower() == False:

would work.

Upvotes: 1

Related Questions