Python Object-Oriented Python Dice Roller Boards

Bashir Orfani
Bashir Orfani
12,495 Points

Let's make all Board instances iterable

Let's make all Board instances iterable so we can loop through their cells attribute. Inside the Board class, define an iter method that yields the cells. If you need help, refer back to the "Emulating Builtins" video.

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