Skip to content
Permalink
Browse files
Fix Bug #1: Blank board
There are actually 2 bugs in this program:

1. We return from the function inside the first for-loop. This
means that the function returns after a single pass through the
loop, before we've had a chance to build up our full board. We
fix this bug by moving the return statement outside of both
loops.

2. We don't reset the `row` variable after each time through
the first for-loop. This means that we keep adding to the same
list, instead of splitting our adding between multiple different
rows. We fix this bug by moving `row = []` inside the first
for-loop so that we reset the row each time.
  • Loading branch information
robert committed Dec 29, 2019
1 parent e6c6d9d commit 8d5aa5fd0d2c584989749b7a191590bed9dc0a90
Showing 1 changed file with 2 additions and 2 deletions.
@@ -10,12 +10,12 @@ def blank_board(width, height):
* https://robertheaton.com/2018/10/09/programming-projects-for-advanced-beginners-3-a/
"""
board = []
row = []
for _ in range(height):
row = []
for _ in range(width):
row.append(None)
board.append(row)
return board
return board

if __name__ == "__main__":
test_board = blank_board(4, 3)

0 comments on commit 8d5aa5f

Please sign in to comment.