Python Forum

Full Version: If, elif, and else statement not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
#Whenever I put something in for the input it always says "That's Good!"
import time
user_action = "user"

print ("wassup")
time.sleep (0.5)
print ("My name is JoeChat. I am a chatbot made by PickleScripts.")
time.sleep (1)
user = input ("How are you doing?")
user = possible_actions = ("good", " good", "well", " well", "bad", " bad", "not good", " not good")

if user == "good" or " good" or "well" or " well": 
  print ("That's good!")
elif user == "bad" or " bad" or "not good" or " not good":
  print ("That's sad. :( I hope you feel better")
else:
  print ("I do not understand")
When I try to put "bad" in the output during the input part, it always says "That's good!"
There are several errors in this code:
  • At line 9, the user = ... statement redefines the 'user' variable that contains the user's reply read at line 8.
  • At line 11, the == operator binds its operands more tightly than or, it means that the expression is equivalent to
if (user == "good") or " good" or "well" or " well": 
This is not what you intended. You could write
if user in ["good", " good", "well", " well"]:
Also note that the expression "good" or " good" or "well" or " well" is the same as "good" for Python, because in a series of or, the value of the whole expression is the first operand which boolean value is not False. If there is no such operand, the value of the whole expression is the last operand.
My full output is,

wassup
my name is JoeChat. I am a chatbot made by PickleScripts.
How are you doing? bad
That's good!


after "How are you doing?" is the input part
Thank You! It works now!