Jan-01-2018, 12:51 AM
I would do this completely differently:
import copy num_rows = 6 num_cols = 5 board = [ ] def make_board(num_rows, num_cols): newrow = [ ] for row in range(num_rows): for col in range(num_cols): newrow.append(0) board.append(newrow) newrow = [ ] def drawboard(): border = ('----' * num_cols) + '-' for row in range(num_rows): print(border) for col in range(num_cols): # print(f'row: {row}, col: {col}') if board[row][col] == 1: cell = '| x ' else: cell = '| ' print(cell, end='') print('|') print(border) def set_cell(row, col): # one based, to make zero based, use: # board[row][col] = 1 board[row-1][col-1] = 1 def clear_cell(row, col): # one based, to make zero based, use: # board[row][col] = 1 board[row-1][col-1] = 0 def columncheck(row): sums = 0 for col in range(num_cols): sums += board[row-1][col] return sums == num_cols def show_results(row): drawboard() if columncheck(row): print('row {} is full\n'.format(row)) else: print('row {} is not full\n'.format(row)) def test_it(): make_board(num_rows, num_cols) # Set first 4 cells of row 6 row = 6 for col in range(4): set_cell(row, col+1) # Now set last cell show_results(row) set_cell(row, 5) show_results(row) if __name__ == '__main__': test_it()run results:
Output:---------------------
| | | | | |
---------------------
| | | | | |
---------------------
| | | | | |
---------------------
| | | | | |
---------------------
| | | | | |
---------------------
| x | x | x | x | |
---------------------
row 6 is not full
---------------------
| | | | | |
---------------------
| | | | | |
---------------------
| | | | | |
---------------------
| | | | | |
---------------------
| | | | | |
---------------------
| x | x | x | x | x |
---------------------
row 6 is full