Noodlez
Noodlez

Reputation: 53

Displaying the print where there is no error

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

Answers (2)

Andreas
Andreas

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

tryingToLearn
tryingToLearn

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

Related Questions