-2

So basically I've been creating a little narrative choice game in python and it has plenty of choices so it has a lot of if this else that but im confused on why they are not working I've tried to move stuff and to no prevail

print("On the large worktop you see a pot filled with a stew it seems rather fresh")
answer2=input("do you eat it?")
if answer2=="yes" or "Yes" or " yes":
    print("The salty taste of the stew makes you splutter but fills your stomach,You gain 3 hp")
else:
    print("Out of caution you leave the stew on the work top")
answer3=input("As you leave the kitchen the tunnel splits into two do you go right or left?")
if answer3=="left" or "Left":
    print("you head down the left route you hear a slow click spikes rise from the ground and impale your foot you loose 3 hp and slowly limp back to the to the start of the passage and make your way down the right side")
else:
    print("you walk down to the end of the passage way")
abolotnov
  • 4,282
  • 9
  • 56
  • 88
  • 1
    You want to format your question properly – Marcin Orlowski Feb 17 '19 at 07:49
  • You need to change `if answer2=="yes"or"Yes"or" yes":` to `if answer2=="yes" or answer2=="Yes" or answer2==" yes":` – Anwarvic Feb 17 '19 at 07:50
  • 1
    Possible duplicate of [Checking multiple values for a variable](https://stackoverflow.com/questions/15851146/checking-multiple-values-for-a-variable) – Mat Feb 17 '19 at 07:52
  • Possible duplicate of [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – TrebledJ Feb 17 '19 at 08:09

3 Answers3

2

Your if statements are problematic in that they are incomplete. Each or that you want to consider must be a full logical expression.

if answer2 == "yes" or answer2 == "Yes" or answer2 == " yes":

if answer3 == "left" or answer3 == "Left":
Rustang
  • 546
  • 5
  • 15
1

Recipes given but I wanted to elaborate just a little bit:

if x == "yes" or " yes " will always return True because the or " yes " is basically asking python if " yes " is None. And it's not None, because it's yes.

As mentioned above, you want to change this to something like:

if answer == "Yes" or answer == " Yes ":
    ...

I would actually recommend taking this little further:

if "yes" in answer.lower():
   ...

This way you check if yes is in the answer (obviously this has downsides to make sure you don't use yes in the other questions) but helps your code be little more maintainable.

abolotnov
  • 4,282
  • 9
  • 56
  • 88
0

When using relational operators in python, make sure that operands are present on both left and right side of the operator when using it with and & or.

Doing something like if answer2=="yes" or "Yes" or " yes":, will always execute the statements present inside the if block, as this will always evaluate to true. Hence, when the user enters the value of answer2 something other than 'Yes' or 'yes', the statements present inside the if statement will not be executed.

print("On the large worktop you see a pot filled with a stew it seems rather fresh")
answer2=input("do you eat it?")
if answer2 == "yes" or answer2 == "Yes":
    print("The salty taste of the stew makes you splutter but fills your stomach,You gain 3 hp")
else:
    print("Out of caution you leave the stew on the work top")
answer3=input("As you leave the kitchen the tunnel splits into two do you go right or left?")
if answer3 == "left" or answer3 == "Left":
    print("you head down the left route you hear a slow click spikes rise from the ground and impale your foot you loose 3 hp and slowly limp back to the to the start of the passage and make your way down the right side")
else:
    print("you walk down to the end of the passage way")
taurus05
  • 2,491
  • 15
  • 28