import random class Board: def __init__(self): self.cols = [] self.called = [] for col in range(5): n = 4 if col == 2 else 5 self.cols.append(random.sample(range(15 * col + 1, 15 * col + 15), n)) self.called.append([False] * 5) self.cols[2][2:2] = [0] self.called[2][2] = True self.border = "+----" * 5 + "+" def print(self): for row in range(5): if row == 0: print(self.border) for col in range(5): caption = self.cols[col][row] if caption == 0: caption = "F" called = "*" if self.called[col][row] else " " print("|%s%2s%s" % (called, caption, called), end = "") print("|") print(self.border) def call(self, n): for col in range(5): for row in range(5): if self.cols[col][row] == n: self.called[col][row] = True def has_bingo(self): for i in range(5): all_col = True all_row = True for j in range(5): if not self.called[i][j]: all_col = False if not self.called[j][i]: all_row = False if all_col or all_row: return True