Elif and if not working or me not understanding [duplicate]

Solution 1:

if passretry == 'yes' or 'Yes':

the above if statement is evaluated as: -

if (passretry == 'yes') or 'Yes':

Now, since 'Yes' is evaluated to True, so, your if statement is always True, and hence you always have to enter new password.


You need to change the condition to: -

if passretry in ('yes', 'Yes'):

likewise, the following elif should be changed to: -

elif passretry in ('no', 'No'):

Solution 2:

This condition:

if passretry == 'yes' or 'Yes':

means "If passretry == 'yes' is true, or 'Yes' is true". 'Yes' is always true, because a non-empty string counts as true. That's why you're always taking the first code path.

You need to spell things out a little more:

if passretry == 'yes' or passretry == 'Yes':

(Or to make your code a bit more general:

if passretry.lower() == 'yes':

which would allow for people shouting YES.)

Solution 3:

You need another complete statement:

passretry == 'yes' or passretry == 'Yes':

The string 'Yes' always evaluates to True.