You're mixing up how the statements are evaluated, specifically your or
.
Here is how it's being evaluated by the interpreter:
# Note: This is evaluated as two separate boolean checks
# as denoted by the parens, rather than one as you are
# intending.
if ("1") or ("2" in User_Input): # "1" is a "truthy" value, e.g. not an empty string, so this is True, and ("2" in User_Input) is not evaluated due to "short circuiting". Meaning no matter what input you get, this if is always True.
Instead what you are trying to see is if the User_Input
string is in any of your values:
if User_Input in ["1", "2"]:
# Only happens when 1 or 2 is the user input
What is happening is called short circuiting. Essentially that means that if the result of a boolean operation can be satisfied by the first evaluation, the rest can be skipped.
if True or False: # Since the first is True, the False is never evaluated
if False and True: # Since this is an "and", and the first condition already failed, the True is never evaluated
Now extrapolate that to an expensive function call (not just built ins). It likely saves a lot of time in a larger function. To demonstrate:
import time
def my_long_func():
"""Waits 5 seconds and returns False"""
time.sleep(5)
return False
def my_true_func():
"""Immediately returns True"""
return True
if my_true_func() or my_long_func():
print("This happens immediately, because of short circuiting.")
If you run ^ in your interpreter, you will see that the print happens immediately and your program never waits on the 5s sleep because it's unnecessary (that function is never called). Essentially it's an easy programming optimization that every language I can think of does automatically for you :)