X-Git-Url: https://harishankar.org/repos/?p=getaclue.git;a=blobdiff_plain;f=crosswordpuzzle.py;h=628392098506ae21438d7e8b561f1cd0ae869148;hp=7ee206fc53ed4bdf20eb0c2c09949eea446a6352;hb=HEAD;hpb=50103f2c3cb70ee8fad1b13e1ab6864a57c36c29 diff --git a/crosswordpuzzle.py b/crosswordpuzzle.py index 7ee206f..6283920 100644 --- a/crosswordpuzzle.py +++ b/crosswordpuzzle.py @@ -93,6 +93,11 @@ class TooLongWordException (Exception): self.word = word self.length = length +# exception for words containing non-alpha characters +class WordCharsException (Exception): + def __init__ (self, word): + self.word = word + # exception for intersecting words class IntersectWordException (Exception): def __init__ (self, word, length): @@ -431,6 +436,10 @@ class CrosswordPuzzle: # if the grid is frozen then abort self.assert_unfrozen_grid () + # if the word has non-alphabetic characters + if not word.isalpha (): + raise WordCharsException (word) + # if the word length greater than totalrows - startrow if len(word) > self.rows - row: raise TooLongWordException (word, len(word)) @@ -485,6 +494,10 @@ class CrosswordPuzzle: # if the grid is frozen then abort self.assert_unfrozen_grid () + # if the word has non-alphabetic characters + if not word.isalpha (): + raise WordCharsException (word) + # is the word length greater than totalcols - startcol? if len(word) > self.cols - col: raise TooLongWordException (word, len(word))