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 trialHasan Ahmad
6,727 PointsIndentationError on build_cells() function
When I open the Python shell and import from dd_game import get_moves
I get an IndentationError on the build_cells()
function. This doesn't much sense to me as the indentation seems to be correct.
code:
def build_cells(width, height):
"""Create and return a width x height grid of two tuples
>>> cells = build_cells(2, 2)
>>> len(cells)
True
"""
cells = []
for y in range(height):
for x in range(width):
cells.append((x, y))
return cells
The error occurs on for y in range(height):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/treehouse/workspace/dungeon/dd_game.py", line 31
for y in range(height):
^
IndentationError: unindent does not match any outer indentation level
1 Answer
Ian Salmon
Courses Plus Student 10,687 PointsI copy/pasted your code into my editor and it worked fine. Hopefully you figured it out!
I used to get indentation errors a lot when using workspaces. I switched over to a different editor (Visual Studio Code) and found that having indentation lines shown really helped me catch/fix these errors with much less frustration. Maybe give it a try?
Hasan Ahmad
6,727 PointsHasan Ahmad
6,727 Pointsi fixed this long ago but thanks for the reply :)