-1

My script for my text-based game cannot properly use the if/elif/else function. When testing, I tried to enter the elif input, but it executes the if input. can someone help me here? I just started studying how to code about 5 months ago, and I dared myself to create a text-based game. Any kind of help would be appreciated.

enter image description here

'''python
    import os
    os.system("cls")
    import time 
    keynumber=0
    os.system("cls")
    time.sleep(5)
    print("THE EXPERIMENT")
    time.sleep(2)
    print("You woke up in a room full of nothing.")
    time.sleep(1)
    print("You don't remember anything up ro this moment.")
    time.sleep(2)
    print("However, you feel the need to escape the room.")
    answer=input("What will you do?")
    if answer==("search room")or("search"):
        print("You decided to search the room")
        time.sleep(2)
        print("You found a key for a door.")
        time.sleep(1)
        print("The key has a label that says 451.")
        time.sleep(1)
        answer=input("Take the key?").lower().strip()
        if answer==("yes")or("take the key"):
            print("You took the key.")
            keynumber=keynumber+1
        elif answer==("no")or("don't take the key"):
            print("You decided to not take the key")
            keynumber=keynumber+0
        else:
            print("Invalid action")
    elif answer==("Look for a door")or("go to door"):
        print("You see a door in front of the room.")
        answer=input("The door has the number 404 labeled on it.").lower().strip()
    else :
        print("You don't understand")
  • 1
    If you post images of code or error messages, please also copy/paste or type the actual code/message directly into the post. While images and screenshots can be helpful for providing context, the post should still be clear and useful without them. Please see [Why may I not upload images of code on SO when asking a question?](//meta.stackoverflow.com/a/285557/208273)—the same reasoning applies to error messages as well. Posts in which essential text is only included in images are likely to be closed for not having enough details. – Ryan M Nov 19 '20 at 02:52
  • oh okay, Thanks for reminding me – Weasley Bugsy Nov 19 '20 at 02:58

1 Answers1

0

Here or on the two strings will evaluate to True because the two strings will be True and or on them will be True, so to compare:

if answer in ["search","search room"]:

Modify other ifs like this

Wasif
  • 14,755
  • 3
  • 14
  • 34