Here is a simplified version of what you have:
action = ""
if action == "stat": # Not true, action == ""
# stuff
elif action == "list": # Not true, action == ""
# stuff
elif action == "retr": # Not true, action == ""
# stuff
else: # Looks like this is where we will end up
exit()
It’s no surprise you are quitting every time, since you have hard coded a condition to make it quit every time.
You say if you remove the action = ""
you get a NameError
saying action
is not defined… that is because you never set it to anything… I’m not sure what you expected the if block to do as written. You need something like this:
action = a_function_that_gets_info_from_user_and_returns_a_string()
This will set action
to something that might pass your if
block.
As a side note, you should’t do screenshots for your questions. Instead, copy/paste; it’s the polite thing to do. Now I have to hand type your code to illustrate what’s wrong instead of copying it myself.
1
solved Problems about python if condition [closed]