Okay I have the below code performing something I don’t want it to do. If you run the program it will ask you “How are you?” (obviously), but when you give a answer to the question that applies to the elif statement, I still get a if statement response. Why is this?
talk = raw_input("How are you?")
if "good" or "fine" in talk:
print "Glad to here it..."
elif "bad" or "sad" or "terrible" in talk:
print "I'm sorry to hear that!"
The problem is that the
oroperator does not do what you want here. What you’re really saying isif the value of "good" is True or "fine" is in talk. The value of “good” is always True, since it’s a non-empty string, which is why that branch always gets executed.