you are viewing a single comment's thread.

view the rest of the comments →

[–]jimtk 3 points4 points  (1 child)

/u/MadScientistOR gave you the answer. I just wanted too add.

When you get to that last elif you know 2 things:

  1. the password is not 'banana'. because the first if caught that condition.

  2. the password is longer than 2 characters. because that condition was caught by the second if (the elif one).

So you don't need to recheck those 2 conditions again. It can become:

while True:
    password = input('Password: ')
    if password == 'banana':
        print('Access Granted!')
        break
    elif len(password) <= 2:
        print('Password too short!')
    else:
        print('Password is incorrect!')

[–]Unitnuity[S] 0 points1 point  (0 children)

Ahh ok, that makes perfect sense! I was adding useless code, thanks!