177k views
2 votes
I need help please. I have started my coding in Python for the Project #2, and as I run it, it either comes up with issues multiple runs until it stop showing it and jumps straight to output, or not. It also isn't letting the commands be written for "West, South, North, East." Please let me know what I've been doing wrong, it's taking so much time and many tries! photos below!

I am expecting for the commands to be written to run!

I need help please. I have started my coding in Python for the Project #2, and as-example-1
I need help please. I have started my coding in Python for the Project #2, and as-example-1
I need help please. I have started my coding in Python for the Project #2, and as-example-2
I need help please. I have started my coding in Python for the Project #2, and as-example-3
I need help please. I have started my coding in Python for the Project #2, and as-example-4
I need help please. I have started my coding in Python for the Project #2, and as-example-5
User Xorsat
by
7.9k points

1 Answer

2 votes

The coding issues are due to syntax errors, such as mismatched quotes and improper function definition inside a print statement. Correcting these will ensure that room directions like "West, South, North, East" are matched with user input to navigate the adventure game.

From the code snippets and the issues you've described, it looks there are a few errors in your Python syntax. You're experiencing issues because of mismatched quotes and misplaced function definitions within the print statement. Furthermore, the room directions like "West, South, North, East" are supposed to match the user input to execute correctly in your adventure game.

Here's a corrected version of your 'show_instructions' and 'player_status' functions with proper syntax:

def show_instructions():
print("\\You have fallen into an unknown cave alongside with the Princess!\\"
"You must escape by venturing and finding resources to help you fight through path!\\"
"There will be 9 rooms, each will either have helpful items, or traps!\\"
"Keep away from the Sorcerers' Bedroom, find the Green Crystal, ladder & Magic Sword to help out!\\"
"You must escape by going back to the dungeon with ladder, without you or Princess dying!\\"
"Move commands: go South, go North, go East, go West.\\")

def player_status(inventory, current_room, rooms):
print('\\Inventory:', inventory)
print('You are currently in the {}'.format(current_room))
if 'item' in rooms[current_room]:
print('You found a', rooms[current_room]['item'])
print("- --- -")

In the corrected code, pay attention to the consistent use of escape sequences for new lines (\\) and the proper closing of print statements, as well as the correct function definition outside of the 'show_instructions' function. Also, ensuring that the 'if' condition correctly accesses the dictionary will resolve the issue regarding commands not being recognized.

User Joseph Farah
by
7.6k points