Reputation: 53
if password:
if blank > 0:
errorcount += 1
if letter > 0:
errorcount += 1
if upper < 1:
errorcount += 1
if lower < 1:
errorcount += 1
if numbdig < 2:
errorcount += 1
if passwords < minimum:
errorcount += 1
print(password, 'is not valid', errorcount, 'errors!')
else:
print(password, 'is valid!')
When there is 0 error the else should print but instead the not valid prints instead.
Upvotes: 3
Views: 35
Reputation: 2521
You should do a check for errorcount
after it has been calculated
if password:
if blank > 0:
errorcount += 1
if letter > 0:
errorcount += 1
if upper < 1:
errorcount += 1
if lower < 1:
errorcount += 1
if numbdig < 2:
errorcount += 1
if passwords < minimum:
errorcount += 1
if errorcount > 0: #check here
print(password, 'is not valid', errorcount, 'errors!')
else: #no error
print(password, 'is valid!')
else: #password is null or false
print(password, 'is null!')
Upvotes: 0
Reputation: 11663
The output is correct because the case of no error means outer if
block i.e.
if password
will be true, so your else
will not be executed.
Inside if password
, there is a print statement which is getting printed.
What you can do is, put a check on your errorcount
variable & print accordingly:
if errorcount >= 1:
print(password, 'is not valid', errorcount, 'errors!')
else:
print(password, 'is valid!')
Upvotes: 1