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 trialPeter Gess
16,553 PointsUsing the _iter_ method but not passing
class Board:
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))
class TicTacToe(Board):
def __init__(self):
super().__init__(3, 3)
def __iter__(self):
for item in self.cells:
yield item
class Board:
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))
class TicTacToe(Board):
def __init__(self):
super().__init__(3, 3)
def __iter__(self):
for item in self.cells:
yield item
2 Answers
Louise St. Germain
19,424 PointsHi Peter,
I copied and pasted the code from your post straight into the challenge, and it worked. Maybe it just has to do with spaces/tabs? Try copying from your forum post back into the challenge, and it might work.
Peter Gess
16,553 PointsThanks..copying and pasting the code again worked. These challenges are so buggy.
pet
10,908 Pointspet
10,908 PointsThe __ iter __ should be in the super class board, not in the subclass TicTacToe. :) Kenneth says to make all Board instances iterable not just TicTacToe.
Louise St. Germain
19,424 PointsLouise St. Germain
19,424 PointsTrue, although the challenge doesn't seem to care either way - I've seen working solutions with _ _ iter _ _ in either one or the other, and both can end up working. Good point though!
pet
10,908 Pointspet
10,908 PointsTrue! As you say it doesn't seem to care about that, another person fixed their code by switching the __ iter __ to be in the class TicTacToe instead of in class Board. :)