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 trialWilfredo Casas
6,174 PointsThere is no monster in my dungeon
Hello, when I run my code I never hit the monster or the door, I am just moving indefinitely. May someone tell me where is my code wrong?
Also, please tell me if my code is not well posted to post the question again, I copied it between '''css (code) '''.
'''css import random
--------------------------
why aren't these inside the getplaces? or why are these here and not inside a function?
CELLS = [(0,2), (1,2), (2,2), (0,1), (1,1), (2,1), (0,0), (1,0), (2,0)]
--------------------------
def get_places(): mo = (random.choice(CELLS)) do = (random.choice(CELLS)) me = (random.choice(CELLS)) if mo == do or mo == me or do==me: return get_places() return mo, do, me
--------------------------
def move_player(me, move): # i thought i had to get the me and move values first x, y = me if move == "left": x -= 1 if move == "right": x += 1 if move == "up": y += 1 if move == "down": y -= 1
return x,y
--------------------------
def get_moves(me): moves = ['left', 'right', 'up', 'down'] # me = (x,y), for getting this, I have to call get locations right? if me[0] == 0: moves.remove('left') if me[0] == 2: moves.remove('right') if me[1] == 2 : moves.remove('up') if me[1] == 0: moves.remove('down') return moves
mo, do, me = get_places() print("Welcome to the Dungeon!") while True:
moves = get_moves(me)
print("Your are at {}, RUN!".format(me)) print("You can move to {}.".format(moves)) #print("press quit to quit the game loser")
move = input("> ")
if move == "quit": break
if move == mo: print("You were eaten by the grue") print("GAME OVER") break elif move == do: print("You won the game") break
elif move in moves:
me = move_player(me, move)
else:
print("** Walls are hard, stop walking into them **")
continue
'''
1 Answer
Daniel Gauthier
15,000 PointsHey Wilfredo,
Switch the apostrophes (''') you're encasing your code in with backticks (```) They're located in the top left hand corner of the keyboard.
Good luck!
Wilfredo Casas
6,174 PointsWilfredo Casas
6,174 PointsAll right, done! https://teamtreehouse.com/community/there-is-no-monster-in-my-dungeon-2