For one, you'll want only one input()
call, and you'll need to store the response in a variable.
Then, you'll need a loop in case to repeat the prompt in case they give an incorrect reply:
while True:
response = input("Do you want to open the door?")
if response == "y":
print("You opened the door. It is a mostly empty room but you spot something in the corner")
break
elif response == "n":
print("You decided not to enter the room, you move down the hallway")
break
print("Please put y or n")
Then, foreseeing there will be many more of this kind of prompt in your game, we can wrap this in a function that returns True or False. (I took the opportunity of also adding lower-casing, so either Y
or y
(or N
/n
) work.)
def prompt_yes_no(question):
while True:
response = input(question).lower()
if response == "y":
return True
elif response == "n":
return False
print("Please put y or n")
if prompt_yes_no("Do you want to open the door?"):
print("You opened the door. It is a mostly empty room but you spot something in the corner")
else:
print("You decided not to enter the room, you move down the hallway")