0
name = input("Hey whats your name")
print ("Oh hey" + name)
mood = input("How are you?")


if mood == ("Good") or ("good") or ("Good thanks") or ("Good thank you"):
  print("Thats great!")


if mood == ("Bad") or ("bad") or ("Not  great"):
  print("Ah thats not good")
  
if mood == ("Ok") or ("Alright") or ("Fine"):
  print("Oh ok well at least its not bad!")

Does anyone know why it’s printing “Ah that’s not good” and “ Oh ok well at least its not bad!” when good is answered?

  • Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – jasonharper Jun 22 '20 at 13:37

2 Answers2

2

You must check the condition like this:

if mood == ("Good") or mood == ("good") or mood == ...

If you don't want to be case sensitive it is better to check like this:

if mood.lower() == "good" or mood.lower() == ...

The problem with your code is that the following expressions of your if will be casted to bool and an non empty string is not False

As bracco23 statet it is even better to use a list and check it like this:

if mood.lower() in ['good', 'good thanks', '...']:
Alexander Kosik
  • 669
  • 3
  • 10
0

In fact, the equality operator applies only to nearby element (check Operators Priority topic). So for each "or" you need next "==" so as to work on booleans instead of strings. E.g:

mood == ("Bad") or mood==("bad") or mood==("Not  great")

Also, don't hesitate to use additional brackets if you hesitate:

(mood == ("Bad")) or (mood==("bad")) or (mood==("Not  great"))

Btw., the brackets around string are not required:

(mood == "Bad") or (mood=="bad") or (mood=="Not  great")
RunTheGauntlet
  • 392
  • 1
  • 4
  • 15