Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHannah Dickey
5,986 PointsHelp! there is a formatting problem with my dungeon game code that I can't find
I have been trying to fix this bug in my code for two days now! I can't seem to figure out where I messed up the formatting the error I have been getting is
File "dungeon_game.py", line 83
print("you are currently in room {}".format(player))
^
IndentationError: unexpected indent
This is the snapshot of my code https://w.trhou.se/qv1valu6h1
Thanks so much!!
2 Answers
Nourez Rawji
3,303 PointsThere's an extra level of indentation in lines 83 to 104.
while True:
draw_map(player)
valid_moves = get_moves(player)
print("you are currently in room {}".format(player))
print("You can move {}".format(", ".join(valid_moves)))
print('Enter QUIT to quit')
move = input(">")
move = move.upper()
if move == 'QUIT':
break
if move in valid_moves:
player = move_player(player,move)
if player == monster:
print("\n** Oh no! The monster got you! Better luck next time!**\n")
break
if player == door:
print("\n**You escaped! Congrats!**\n")
break
else:
input("\n** Walls are hard! Don't run into them! **\n")
clear_screen()
Notice that print(...)
is indented farther than the line above it. Go through your code and move everything back into place, and that should do the trick. Python can be really finnicky about indenting, and a lot of the times it's easy to miss an over or under-indented line or block of code when looking over it by eye.
Hannah Dickey
5,986 Pointsthanks so much It works great now! :)
Nourez Rawji
3,303 PointsIf my suggestion worked for you I'd appreciate you marking it as the best answer.
And as always, glad to help :)
Nourez Rawji
3,303 PointsNourez Rawji
3,303 PointsJust to clarify, your fixed code should look like this