mercredi 18 novembre 2020

My python script for a text game can't properly execute the if/else function [duplicate]

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")

Aucun commentaire:

Enregistrer un commentaire