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

Kohei Ashida
Kohei Ashida
4,882 Points

Why should I get "Bammer!" with this coding?

I've come to the correct answer by searching community as follows

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)

but I thought my coding below would also work. Why is this wrong?

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):
        super().__init__(width=3, height=3)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Kohei Ashida ! The reason the second version of the code is incorrect is that it would require you to send in two arguments to create a TicTacToe board. But there's never a time when we want the TicTacToe board to be a 5 x 5 or 10 x 20 etc. A classic game of TicTacToe is always 3 x 3.

So using that code, to create a new TicTacToe board you would need to do something like:

my_tictactoe = TicTacToe(3, 3)

But since it's always going to be a 3 x 3 there is no reason for the arguments. We want to do something like:

my_tictactoe = TicTacToe()

And it will make a classical (3 x 3) TicTacToe board without requiring any other information :smiley:

Hope this helps! :sparkles:

Kohei Ashida
Kohei Ashida
4,882 Points

Thank you so much, Jennifer!