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

Naga pavan kumar kalepu
Naga pavan kumar kalepu
5,909 Points

Getting Error as "TicTacToe` isn't a 3x3 board" for the challenge

Create a new Board subclass named TicTacToe. Have it automatically be a 3x3 board by automatically setting values in the init.

I have tried in two ways below, but both didn’t work out got  TicTacToe` isn't a 3x3 board,

Please check my below code and please suggest me what I have done wrong?

You can check challenge at this link -> https://teamtreehouse.com/library/objectoriented-python-2/dice-roller/boards

——————————————————————————————————————————————————

Default code given is:

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, z))

——————————————————————————————————————————————————

My code:

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, width=1, length=1, height=1): super().init(width=width, height=height) self.length = length self.cells = [] for z in range(self.length): for y in range(self.height): for x in range(self.width): self.cells.append((x, y, z))

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, width=1, length=1, height=1):
        super().__init__(width=width, height=height)
        self.length = length
        self.cells = []
        for z in range(self.length):
            for y in range(self.height):
                for x in range(self.width):
                    self.cells.append((x, y, z))

1 Answer

Steven Parker
Steven Parker
231,248 Points

You're working way to hard!

You have the right idea to override "__init__", but all your version needs to do is call the base version and pass it the desired width and height. There's no need to replicate what the base version does.

Naga pavan kumar kalepu
Naga pavan kumar kalepu
5,909 Points

Thanks for response Steven,

As per the question asked "Create a new Board subclass named TicTacToe. Have it automatically be a 3x3 board by automatically setting values in the init."

Given Base Class creating cells of 2X2 -> (x,y). So I thought of overriding init by adding additional parameter length and created 3X3 cells

But as you mentioned, I have tried by just calling as below:

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, width, height, length): super().init(width=width, height=height) self.length = length

But still didn't work and got "Bummer! Try again!"

Steven Parker
Steven Parker
231,248 Points

The new class doesn't need to take any arguments (and should not require any) to create an instance, it just needs to pass along the correct values when it calls the base version of "__init__".