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 trialTatiane Lima
6,738 PointsWhats 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(_)
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)
2 Answers
Louise St. Germain
19,424 PointsI 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
6,738 PointsUsually 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.
csr13
33,293 PointsNo 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.
Tatiane Lima
6,738 PointsOh, it is good to know about it! Thanks again for the advice @carla91. :)
csr13
33,293 Pointscsr13
33,293 Points__iter__
method to TicTacToe instead of giving it to Board.