So in the if-statement, I want to print a message if the player doesn't input the correct things. The problem is that when I start up the code and type something random, it jumps to the first if where it checks yes and moves on. It even replied to the next function for me. Is there a way to fix this?
import time
yes_no = ['yes', 'y', 'no', 'n']
directions = ['north', 'n', 'south', 's', 'east', 'e', 'west', 'w']
else_msg = "Invalid command"
def start():
print("-------------------------------")
print("Welcome to Haunted Funhouse")
print("Do you want to proceed? (y/n)")
cmd = input(">")
if cmd in yes_no:
if cmd == "yes" or "y":
time.sleep(1)
print("\n------------------")
print("Get ready")
print("--------------------\n")
starting_room()
elif cmd == "no" or "n":
time.sleep(1)
print("Okay, shutting down")
quit()
else:
print(else_msg)
def starting_room():
print("-----------Start-----------")
print("You stand in a octagon room")
print(
"There are windows to the northwest, northeast, southeast, southwest")
print("There are doors to the:\n- North\n- South\n- East\n- West")
print("---------------------------------------------------------")
print("Where do you want to go? (n/s/e/w)")
cmd = input(">")
if cmd in directions:
if cmd == "north" or "n":
time.sleep(1)
print("You enter through the north door")
elif cmd == "south" or "s":
time.sleep(1)
print("You go through the south door")
elif cmd == "west" or "w":
time.sleep(1)
print("You enter through the west door")
elif cmd == "east" or "e":
time.sleep(1)
print("You enter through the east door")
else:
print(else_msg)
start()
I've tried changing '''if cmd not in yes_no''' to '''if cmd in yes_no''', but it didn't work. I ran it through Thonny and the code checker said it was fine