1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Rep Power

    Question About Incorrect Word Count in Word Game


    I'm having trouble with a particular function I am developing for a word game that will simply count the number of words present in the board.

    The thing is, that my known example for how the function SHOULD act (aka what the instructor has already pre-defined as a true condition) is not working, and I'm getting the value of 1 for the known example instead of 3 words.

    I'm thinking that the problem lies within the original function OR the function it refers to that will check to see if that word is in fact a word.

    Thanks a bunch for reading my post, and have an amazing day, guys!

    Here's my code for the num_words_on_board portion of my project:

    def num_words_on_board(board, words):
        """ (list of list of str, list of str) -> int
        Return how many words appear on board.
        >>> num_words_on_board([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], ['ANT', 'BOX', 'SOB', 'TO'])
        num_words = 0
        for x in range(len(board)):
            # This will search through the entire length of the board
            if board_contains_word(board,words) == True:
                # This will pass the board to the board_contains function to see
                # if in fact it IS a word
                num_words = num_words + 1
                return num_words

    Here is the function that it references aka board_contains_word, that will check to see if in fact that board itself is a word:
    def board_contains_word(board, word):
        """ (list of list of str, str) -> bool
        Return True if and only if word appears in board.
        Precondition: board has at least one row and one column.
        >>> board_contains_word([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 'ANT')
        >>> board_contains_word([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 'SOB')
        x = ''
        for word in range(len(board)):
            # This is a for loop that looks throughout the entire length of the board
            if x in make_str_from_row(board,word):
                return True
        return False
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Rep Power
    "return num_words" is executed the first time "if board_contains_word(board,words)" is True i.e. indented too far. Also, all the code under
        for x in range(len(board)):
    (board and words) never changes so you do the same exact thing len(board) times. Give us an example of what "board" and "words" contain for further assistance.
    Last edited by dwblas; September 27th, 2013 at 11:14 PM.

IMN logo majestic logo threadwatch logo seochat tools logo