davecom/ClassicComputerScienceProblemsInPython

Off-by-one error in word_search

herwinvw opened this issue · 1 comments

In the word_search.py (chapter 3)
columns: range = range(col, col + length + 1) and
rows: range = range(row, row + length + 1)
should be
columns: range = range(col, col + length)
rows: range = range(row, row + length)

The original code (regularly but not always) throws the following error when generating a 7x7 grid:

IndexError Traceback (most recent call last)
in
19 for index, letter in enumerate(word):
20 (row, col) = (grid_locations[index].row, grid_locations[index].column)
---> 21 grid[row][col] = letter
22 display_grid(grid)

IndexError: list assignment index out of rang

Thanks, @herwinvw. I've been able to reproduce this and I think you are correct. I'll likely be updating the code.