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 trial

Python Object-Oriented Python Dice Roller Boards

Peter Gess
Peter Gess
16,553 Points

Using 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
boards.py
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
Louise St. Germain
19,424 Points

Hi 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.

pet
pet
10,908 Points

The __ 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
Louise St. Germain
19,424 Points

True, 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
pet
10,908 Points

True! 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. :)

Peter Gess
Peter Gess
16,553 Points

Thanks..copying and pasting the code again worked. These challenges are so buggy.