Python Object-Oriented Python Dice Roller Boards

Kohei Ashida
Kohei Ashida
4,881 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 Staff

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,881 Points

Thank you so much, Jennifer!