Conditionals don't work like that. You need something like:
# Check each condition explicitly
if user_input != 'h' and user_input != 'l' and user_input != 'c':
Or:
# Check if the input is one of the elements in the given list
if user_input not in ["h", "c", "l"]:
Your current approach is understood as
if (user_input != 'h') or ('l') or ('c'):
And since l
and c
are truthy, that branch will always execute.
You might also consider using elif
, so your conditions would become the following:
while True:
if user_input == 'h':
High=Guess
Guess= ((High-Low)/2)
elif user_input == 'l':
Low=Guess
Guess= ((High-Low)/2)
elif user_input == "c":
# We're done guessing. Awesome.
break
else:
print('Sorry, I did not understand your input.')