0

In a text-based adventure I'm programming, I've been coding IF statements to allow for multiple lines of conditionals, like so:

    if certain_input == (
                       "examine bed" or "look at bed" or "look bed" or "look straw" or "inspect straw" or
                       "inspect bed" or "search bed" or "examine straw" or "look at straw"
                      ):
        print("this input has been fulfilled")

The only conditionals that work in this format are "examine bed" and "inspect bed". Every other listed option returns an error when used. Is there something I am missing?

1
  • "inspedc bed" does not return True here, only "examine bed" Sep 26, 2020 at 7:01

1 Answer 1

5

try putting all these items in a list and using in:

option_lst = ["examine bed", "look at bed", "look bed", "look straw", "inspect straw", "inspect bed", "search bed", "examine straw", "look at straw"]
certain_input = "look at bed"
if certain_input in option_lst:
    print("this input has been fulfilled")

this makes your code easier to change in the future and more elegant.

btw the statement:

x = ("examine bed" or "look at bed" or "look bed" or "look straw" or "inspect straw" or
     "inspect bed" or "search bed" or "examine straw" or "look at straw")

returns "examine bed" since "examine bed" is not an empty string and therefore is truth like, so you'd be only comparing with "examine bed".

Not the answer you're looking for? Browse other questions tagged or ask your own question.