Even once you fixed the mis-cased if and improper indentation in your code, it wouldn't work as you probably expected. To check a string against a set of strings, use in. Here's how you'd do it (and note that if is all lowercase and that the code within the if block is indented one level).

One approach:

if answer in ['y', 'Y', 'yes', 'Yes', 'YES']:
    print("this will do the calculation")

Another:

if answer.lower() in ['y', 'yes']:
    print("this will do the calculation")
Answer from Daniel DiPaolo on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_conditions.asp
Python If Statement
Python can evaluate many types of values as True or False in an if statement. Zero (0), empty strings (""), None, and empty collections are treated as False.
Discussions

Comparing strings in if statements
if pizza == str(yes): This will produce an error message saying that yes has not been declared. Look up the difference between variables and strings. More on reddit.com
🌐 r/learnpython
11
1
June 20, 2024
Using or for multiple strings in an if statement
Instead of using or go with in: user_choice = input("Choice: ") if user_choice.lower() in ('go east', 'east', 'head east'): #do stuff Or alternatively use the concept of keywords (e.g. 'east', 'west', 'pickup', 'drop' etc) and do this: if 'east' in user_choice.lower(): #do stuff More on reddit.com
🌐 r/learnpython
21
4
November 30, 2021
If statements in functions
I am relatively new to python but am currently stuck on this program. My goal is too validate a credit card number by testing the length and the first number I have figured out the length requirement but as you can see in the code below I use the == sign to check if the first digit is equal ... More on discuss.python.org
🌐 discuss.python.org
4
0
September 20, 2023
Python: How can I use a String for a If-Statement? - Stack Overflow
In Python I have to build a (long) if statement dynamically. How can I do this? I tried the following test code to store the necessary if-statement within a string with the function " More on stackoverflow.com
🌐 stackoverflow.com
🌐
Delft Stack
delftstack.com › home › howto › python › if with string in python
if Statement With Strings in Python | Delft Stack
February 22, 2025 - While this usually works for short strings due to Python’s string interning, it’s generally recommended to use == for string content comparison. Mastering the use of if statements with strings in Python opens up a world of possibilities for text processing and decision-making in your code.
🌐
Quora
quora.com › How-do-you-use-a-Python-if-statement-with-string-as-condition-Python-virtualenv-development
How to use a Python if statement with string as condition (Python, virtualenv, development) - Quora
Answer (1 of 4): How do you use it? You just use it: [code]>>> s = 'Spam' >>> if s: ... print(s) Spam [/code]I’m guessing what you really wanted to ask is what it means when you do this. The Python if statement checks whether the condition is “truthy” or “falsy”. For built-in and ...
🌐
Reddit
reddit.com › r/learnpython › comparing strings in if statements
r/learnpython on Reddit: Comparing strings in if statements
June 20, 2024 -

I'm writing this through my phone, forgive me if the proper indentation is incorrect, as it displays differently in my screen, and auto correct might mess something up. I'm getting the following error: Name error = name 'yes' is not defined. I dug around, and this usually happens when the variable is not defined, or if the value is pulled before the variable being defined. I don't think the issue is with my logic, but moreso with the syntax. I even tried specifying that it was a string value, as that was a problem once, but it doesn't seem to work either. If I could get any help, I'd appreciate it.

Here's the code that's giving the error:

pizza = str(input("Do you like pizza? "))

If pizza == str(yes): print("User Likes Pizza") elif pizza == no: print("user does not like pizza") else print("Please Give Valid response")

🌐
Luc
anh.cs.luc.edu › handsonPythonTutorial › ifstatements.html
3.1. If Statements — Hands-on Python Tutorial for Python 3
Elaborate your program congress.py so it obtains age and length of citizenship and prints out just the one of the following three statements that is accurate: You are eligible for both the House and Senate. You eligible only for the House. You are ineligible for Congress. Here are a few more string methods useful in the next exercises, assuming the methods are applied to a string s: ... returns True if string s starts with string pre: Both '-123'.startswith('-') and 'downstairs'.startswith('down') are True, but '1 - 2 - 3'.startswith('-') is False.
🌐
Medium
medium.com › @pathakvikas034 › exploring-strings-and-conditional-statements-in-python-af49c3ade3b1
🔍 Exploring Strings and Conditional Statements in Python:- | by VIKAS PATHAK | Medium
March 15, 2024 - String Methods: Python provides ... based on specific conditions. If Statement: The `if` statement executes a block of code if a specified condition is true:...
Find elsewhere
🌐
Mimo
mimo.org › glossary › python › if-statement
Python If Statement: Master Conditional Logic | Learn Coding
Indentation is Mandatory: Python uses indentation (whitespace) to define code blocks. The code indented under an if, elif, or else statement is what will be executed. Incorrect indentation will cause an error. Conditions are Based on "Truthiness": The condition doesn't have to be a strict boolean (True/False). Any "truthy" value (like a non-empty list or a non-zero number) will pass, while any "falsy" value (like an empty string "", the number 0, or None) will fail.
🌐
PythonForBeginners.com
pythonforbeginners.com › home › conditional statements in python
Conditional statements in Python - PythonForBeginners.com
August 27, 2020 - # This program compares two strings. # Get a password from the user. password = raw_input('Enter the password: ') # Determine whether the correct password # was entered. if password == 'hello': print'Password Accepted' else: print'Sorry, that is the wrong password.' Let’s show one more examples, in which will also make use of the elif statement. #!/usr/bin/python number = 20 guess = int(input('Enter an integer : ')) if guess == number: print('Congratulations, you guessed it.') elif guess < number: print('No, it is a little higher than that') else: print('No, it is a little lower than that')
🌐
Dataquest
dataquest.io › home › blog › tutorial: using if statements in python
How to Use IF Statements in Python (if, else, elif, and more) – Dataquest
November 24, 2024 - If this condition isn't met, then we go for a walk in the forest (elif statement). Finally, if neither condition is met, we’ll stay home (else statement). Now let’s translate this sentence into Python. In this example, we're going to use strings instead of integers to demonstrate the ...
🌐
Reddit
reddit.com › r/learnpython › using or for multiple strings in an if statement
r/learnpython on Reddit: Using or for multiple strings in an if statement
November 30, 2021 -

**solved**

So I'm trying to use or in an if statement, a bit of pretext, I'm using pycharm to try and make a sort of text adventure game, and I want to allow for more than one version of the same thing for example "go east" or "east" But when I use or it just gives me all of the if statements at once and I'm not sure what to do

here's my code:

import random
health = random.randint(10, 38)
print("Note: please always put go in front of your direction")
while health > 0:
    print("""You are in a flat plain with little memory of what you were doing.
To the north is a run down barn with what seems to be a living scarecrow.
To the south is a small river, you see some fish swimming around in it.
To the east is what seems to be a small forest.
To the west you only see more flatland"""
     )
    direction = input("what do you do? ").lower()
    if direction == "go west" or "west":
        print("""You head west, only finding more flatland.
     Nothing interesting here, so you head back""")
    if direction == "go south" or "south":
        print("""You reach the river, the sound of the water calmly being splashed about by the fish sooths you.
        you watch the fish for a while before heading back.""")
    if direction == "go east" or "east":
        print("""You head to the dark forrest, unable to see in front of you,
        You hear a loud moan come from behind you, it's a zombie!
        You try to run away but trip on a fallen branch,
        just as you think it's the end you feel something grab you and lead you out of the forrest""")
    if direction == "go north" or "north":
        print("""As you approach the run down barn, you see the scarecrow plowing a field.
Nearby there are animal pens, overgrown with weeds and grass, it looks like nothing has been in them for a while.
As you reach the barn you see a run down house not to far away but before you can do anything the scarecrow pipes up.
'Well it's been a long time since I saw a friendly face aroun' these parts'
you explain what you remember to the scarecrow.
'I'll join you on your journey if you can find ma hat, it's somewhere in the forest over there'""")
        help = input("Will you help the scarecrow? ")
        if help == "yes":
            print("""You enter the forest and begin to search around, you can go west back to the farm.
North or south around the edge of the forrest.
Or east, deeper into the forrest""")
            direction2 = input("which way will you go? ")
            if direction2 == "go east" or "east":
                print("""As you head deeper into the small forrest it quickly becomes harder and harder to see.
After a minute its almost impossible to see in front of you.
You suddenly hear a loud moan coming from nearby.
'W-was that zombie?'""")
                decision = input("will you run away? ")
                if decision == "yes" or "run away":
                    print("""you run out of the forrest chased by the zombie to the treeline,
                 it appears it cant leave the forrest, the scarecrow rushes over upon seeing you bolt out of the forrest.
                'well I'll be damned, that's ma hat, i'm sure you can take it out, so here take my sword'
                 the scarecrow hands you a sword, a little worse for ware but it'll still kill things""")
                else:
                    print(f"""you pick up a stick from the ground,
flailing it around in front of you you manage to hit the zombie dealing {random.randint(0, 5)} damage
the zombie bites you dealing {random.randint(2, 8)} """)

                    fight = input("what will you do? ")
                    if fight == "check health" or "health":
                        print (health)
        else:
            print("""You decide not to help the scarecrow by punching him in the face,
but before you can even move your hand the scarecrow impales the hoe he was using in your arm
'No one messes with sam the scarecrow, bitch!'
you lay there bleeding out, unable to move""")
            break

to solve this problem u/newunit13 suggested I use in instead of or e.g

if direction in "go west"  "west" "head west":
        print("""You head west, only finding more flatland.
     Nothing interesting here, so you head back""")

🌐
GeeksforGeeks
geeksforgeeks.org › python › conditional-statements-in-python
Conditional Statements in Python - GeeksforGeeks
They allow programs to execute different blocks of code depending on whether a condition evaluates to True or False. If statement is used to execute a block of code only when a specified condition evaluates to True.
Published   June 8, 2026
🌐
freeCodeCamp
freecodecamp.org › news › python-else-if-statement-example
Python Else-If Statement Example
July 1, 2022 - For this, you use the equality ... to the string Python. language = input("Please enter your favorite programming language: ") if language == "Python": print("Correct! Of course it is Python!") I run my code, and when the prompt “Please enter your favorite programming language:” appears, I enter Python. ... # output # Please enter your favorite programming language: Python # Correct! Of course it is Python! The condition (language == "Python") is True, so the code in the if statement ...
🌐
Python.org
discuss.python.org › python help
If statements in functions - Python Help - Discussions on Python.org
September 20, 2023 - I am relatively new to python but am currently stuck on this program. My goal is too validate a credit card number by testing the length and the first number I have figured out the length requirement but as you can see in the code below I use the == sign to check if the first digit is equal ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-conditional-statements-if-else-elif-in-python
How to Use Conditional Statements in Python – Examples of if, else, and elif
December 11, 2025 - If the year is not divisible by 4, the code block indented below the else statement of the outer if statement will be executed, printing the message "is not a leap year." string = "hello, world" char = "w" if char in string: print("The string contains the character", char) else: print("The string does not contain the character", char)
🌐
Squash
squash.io › how-to-use-inline-if-statements-for-print-in-python
How to Use Inline If Statements for Print in Python - Squash Labs
November 25, 2023 - In this example, the inline if statement is used within the f-string to conditionally include the message "greater than 5" if x is greater than 5, or "less than or equal to 5" otherwise.
🌐
Python.org
discuss.python.org › python help
String not recognized in if statement - Python Help - Discussions on Python.org
September 28, 2024 - Hi ! I am trying to create a definition allowing the user to find the position of the start codon in a sequence. My variable s_codon is supposed to include three letters at position (0,3), then move on to the following at position (1,4), then (2,5), etc, and check if s_codon equals to “AUG” (the start codon).