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

Tatiane Lima
Tatiane Lima
6,738 Points

Whats is going on? Make the cell atribute iterable

i can to understand whats is wrong in my code. I've already test it on jupter notebook and it works perfectly. I tested with this code:

ttt = TicTacToe()
ttt.cells

for _ in ttt.cells:
    print(_)
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))
    def __iter__(self):
        yield from self.cells             

class TicTacToe(Board):
    def __init__(self, width=3, height=3):
        super().__init__(width=width, height=height)
  • You code worked when I copied and pasted it into the challenge, you can also do the following if it is still not working, it will still pass the challenge --> Give the __iter__ method to TicTacToe instead of giving it to Board. :star:

2 Answers

Louise St. Germain
Louise St. Germain
19,424 Points

I think the code looks OK, and it works for me when I copy this as is, right into the challenge. It might be the fairly common issue of mixed tabs and spaces in the challenge editor. (Check your Jupyter setup - maybe it's using tabs instead of spaces?)

Tatiane Lima
Tatiane Lima
6,738 Points

Usually when it has mixed tabs and spaces jupyter notebook shows an arrow to represent a tab. I had this problem, at first but i fixed and it didn't works. So now i did what @carlaos91 told (thanks, man), give the iter method to TicTacToe, and it finally work.

Thanks for answer me, Louise.

No problem.

It is also possible that what Louise said is the case here, usually, not only with the Treehouse challenge input fields but also in an outside python environment the accidental occurrence of extra tabs and spaces affect the execution of statements.

In the future, here on Treehouse and elsewhere you code always check to have no extra tabs between functions, classes, and functions of classes.

Happy coding. :star:

Tatiane Lima
Tatiane Lima
6,738 Points

Oh, it is good to know about it! Thanks again for the advice @carla91. :)