Question
how do i fix this code print("Welcome to the Text-based Adventure Game!")
print("You wake up in a dark room with no memory of how you got there.")
print("Your mission is to escape the room by finding a key.")
print("In each step, you will be presented with options to choose from.")
has_key = False
print("What would you like to do?")
print("1. Look around the room")
print("2. Search the dresser")
choice = input("Enter your choice (1 or 2): ")
if choice = "1":
print("You look around the room and find a key on the floor!")
has_key = True
elif choice == "2":
if has_key:
print("You already searched the dresser and found nothing.")
else:
print("You search the dresser and find a key!")
has_key = True
else:
print("Invalid choice. Please enter 1 or 2.")
if has_key:
print("Congratulations! You have found the key and escaped the room.")
break
print("You wake up in a dark room with no memory of how you got there.")
print("Your mission is to escape the room by finding a key.")
print("In each step, you will be presented with options to choose from.")
has_key = False
print("What would you like to do?")
print("1. Look around the room")
print("2. Search the dresser")
choice = input("Enter your choice (1 or 2): ")
if choice = "1":
print("You look around the room and find a key on the floor!")
has_key = True
elif choice == "2":
if has_key:
print("You already searched the dresser and found nothing.")
else:
print("You search the dresser and find a key!")
has_key = True
else:
print("Invalid choice. Please enter 1 or 2.")
if has_key:
print("Congratulations! You have found the key and escaped the room.")
break
Answers
GPT 3.5
To fix the code, you need to correct the indentation and syntax errors. Here is the corrected code:
```python
print("Welcome to the Text-based Adventure Game!")
print("You wake up in a dark room with no memory of how you got there.")
print("Your mission is to escape the room by finding a key.")
print("In each step, you will be presented with options to choose from.")
has_key = False
print("What would you like to do?")
print("1. Look around the room")
print("2. Search the dresser")
choice = input("Enter your choice (1 or 2): ")
if choice == "1":
print("You look around the room and find a key on the floor!")
has_key = True
elif choice == "2":
if has_key:
print("You already searched the dresser and found nothing.")
else:
print("You search the dresser and find a key!")
has_key = True
else:
print("Invalid choice. Please enter 1 or 2.")
if has_key:
print("Congratulations! You have found the key and escaped the room.")
```
Note: The `break` statement at the end of your code is unnecessary as you are not using any loops.
```python
print("Welcome to the Text-based Adventure Game!")
print("You wake up in a dark room with no memory of how you got there.")
print("Your mission is to escape the room by finding a key.")
print("In each step, you will be presented with options to choose from.")
has_key = False
print("What would you like to do?")
print("1. Look around the room")
print("2. Search the dresser")
choice = input("Enter your choice (1 or 2): ")
if choice == "1":
print("You look around the room and find a key on the floor!")
has_key = True
elif choice == "2":
if has_key:
print("You already searched the dresser and found nothing.")
else:
print("You search the dresser and find a key!")
has_key = True
else:
print("Invalid choice. Please enter 1 or 2.")
if has_key:
print("Congratulations! You have found the key and escaped the room.")
```
Note: The `break` statement at the end of your code is unnecessary as you are not using any loops.