Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying the print where there is no error

Tags:

python-3.x

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.

like image 923
Noodlez Avatar asked Jan 29 '26 08:01

Noodlez


1 Answers

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!') 
like image 129
tryingToLearn Avatar answered Jan 31 '26 23:01

tryingToLearn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!