try..except
blocks are used if you or the system raise an exception. The except
block will not be executed if the try
block finishes successfully. In your case it does, your program simply does not go into the if
blocks.
To get the expected result, rewrite the if statements as follows:
if encrypt == 'e':
...
elif encrypt == 'd':
...
elif encrypt == 'q':
break
else:
print("")
print("INCORRECT INPUT!")
print("")
This way, you combine all the conditions, and have a "default" statement. The else
after elif
s will enter if none of the previous elif
s AND the first if
are entered (which is basically saying that none of the conditions are true).
If you don't use elif
and use only if
(as in your original code), the condition chain is broken and the else
at the end will catch all cases in which encrypt != "q"
, even if it is "e" or "d".