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 trialliamthornback2
9,618 PointsDoesn't work here, but my code works on an online compiler
Here is my code. My error message was simply "Bummer: TicTacToe' isn't itterable"
I couldn't see what I did wrong so I tested my code here: https://www.onlinegdb.com/online_python_compiler
these are the lines I added for testing:
myBoard = TicTacToe()
for item in myBoard:
print(item)
class Board(list):
def __init__(self, width, height):
self.width = width
self.height = height
self.cells = []
for y in range(self.height):
for x in range(self.width):
self.cells.append((x, y))
def __iter__(self):
yield from self.cells
class TicTacToe(Board):
def __init__(self):
super().__init__(width=3, height=3)
2 Answers
Steven Parker
231,198 PointsYour "__iter__
" code is good, but you also changed the definition of "Board" to make it a subclass of "list", which is not part of the instructions.
Put it back to being a stand-alone class and you will pass the challenge.
liamthornback2
9,618 PointsOkay well I tried it again and your code worked. Thanks.
Steven Parker
231,198 PointsGlad to help, but the code is all yours. I just gave you some hints on fixing it.
Congratulations on resolving the issue, and happy coding!
liamthornback2
9,618 Pointsliamthornback2
9,618 PointsThe code started with Board as a subclass of list...
And how would the iter method work w/o the Board class inheriting from the List class?
Steven Parker
231,198 PointsSteven Parker
231,198 PointsWhen you start the challenge, it gives you this initial code to work with:
Note that the "Board" class is not a subclass of something else.
And the function of the "
__iter__
" method is not dependent on inheritance. Any object can be iterable.