def __init__ (self, row, col):
self.pos = (row, col)
+# exception when a word number is not found in the grid
+class NoNumberException (Exception):
+ def __init__ (self, num):
+ self.num = num
+
# exception when no words are present in the grid
class NoWordsException (Exception):
def __init__ (self):
return clues
+ # getting an across word at a number (note that the grid should be
+ # frozen for calling this otherwise a FrozenGridException will be raised)
+ def get_word_across_at_num (self, num):
+ # assert that the grid is frozen
+ self.assert_frozen_grid ()
+
+ # traverse the grid
+ for row in range (self.rows):
+ for col in range (self.cols):
+ if self.data[row][col].numbered == num:
+ word = self.get_word_across (row, col)
+ return word
+
+ # if number is not found
+ raise NoNumberException (num)
+
+ # getting a down word at a number (note that the grid should be frozen
+ # for calling this otherwise a FrozenGridException will be raised)
+ def get_word_down_at_num (self, num):
+ # assert that the grid is frozen
+ self.assert_frozen_grid ()
+
+ # traverse the grid
+ for row in range (self.rows):
+ for col in range (self.cols):
+ if self.data[row][col].numbered == num:
+ word = self.get_word_down (row, col)
+ return word
+
+ # if number is not found
+ raise NoNumberException (num)
+
+ # getting the position of a number on the grid (note that the grid should
+ # be frozen for calling this otherwise a FrozenGridException will be raised)
+ def get_position_of_num (self, num):
+ # assert that the grid is frozen
+ self.assert_frozen_grid ()
+
+ # traverse the grid
+ for row in range (self.rows):
+ for col in range (self.cols):
+ if self.data[row][col].numbered == num:
+ return (row, col)
+
+ # if number is not found
+ raise NoNumberException (num)
+
# getting a down word at a position
def get_word_down (self, row, col):
# if index is out of bounds