From 919165557428aec33c0032da56aaa9b492726460 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 12 Apr 2016 21:15:51 -0400 Subject: [PATCH] move Board class into "bingo" module --- bingo-analysis.py | 29 ++--------------------------- bingo/__init__.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 bingo/__init__.py diff --git a/bingo-analysis.py b/bingo-analysis.py index f29684a..97212c2 100755 --- a/bingo-analysis.py +++ b/bingo-analysis.py @@ -1,35 +1,10 @@ #!/usr/bin/python3 import random - -class Board: - def __init__(self): - self.cols = [] - 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.cols[2][2:2] = [0] - self.border = "+----" * 5 + "+" - self.called = {0} - - 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.cols[col][row] in self.called else " " - print("|%s%2s%s" % (called, caption, called), end = "") - print("|") - print(self.border) - - def call(self, n): - self.called.add(n) +import bingo if __name__ == "__main__": - b = Board() + b = bingo.Board() b.call(1) b.call(2) b.call(40) diff --git a/bingo/__init__.py b/bingo/__init__.py new file mode 100644 index 0000000..f7beb86 --- /dev/null +++ b/bingo/__init__.py @@ -0,0 +1,27 @@ +import random + +class Board: + def __init__(self): + self.cols = [] + 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.cols[2][2:2] = [0] + self.border = "+----" * 5 + "+" + self.called = {0} + + 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.cols[col][row] in self.called else " " + print("|%s%2s%s" % (called, caption, called), end = "") + print("|") + print(self.border) + + def call(self, n): + self.called.add(n)