Question

In: Computer Science

Write a function checkvertical(board, word, row, col), which returns True if the word word can be...

Write a function checkvertical(board, word, row, col), which returns True if the word word can be added to the board starting at position board[row][col] and going down. The restrictions are (1) it has to fit entirely on the board, (2) it has to intersect and match with one or more non-blank letters on the board, and (3) it cannot change any letters on the board, other than blanks (that is, overlapping mismatches are not allowed).

My program isn't working :( Can anyone fix the program?

My program:

def checkvertical(board, word, row, col):

if len(word) > 20 - row:

return False

matchesoneletter = False

for k in range(len(word)):

wordletter = word[k]

boardletter = board[row + k][col]

if wordletter == boardletter:

matchesoneletter = True

if boardletter == blank:

continue

elif boardletter != wordletter:

return False

return matchesoneletter

Solutions

Expert Solution

def checkvertical(board, word, row, col):
   #considering board size of 20 x 20 seeing your code.
   #if the len(word) doesn't fit vertically at that position.
   if len(word)>20-row:
       return False
   #else check for each letter in word matches with the
   #letter on the bord starting index(row) or there is blank space
   #if not so exit by returning false
   #if it successfully runs till the end, it implies,
   #the word can be fit there.
   for i in range(len(word)):
       # here i am considering -1 representing blank space in your board
       # if not so change that value
       if word[i] == board[row+i][col] or board[row+i][col]==-1:
           continue
       else:
           return False
   return True

    #refer above image for indentation.
   # I am unable to understand the logic you want to implement
   # with your code. hence I am providing my code.
   # If you have any doubt ask in the comments section below.
   # Also please leave your rating. Thank you!


Related Solutions

PYTHON: Write a function named is_palindrome() that returns boolean True if a word or phrase is...
PYTHON: Write a function named is_palindrome() that returns boolean True if a word or phrase is a palindrome, and boolean False if it is not. The palindromes for this problem are contained in the list below. You must use this list in your solution. Use a for loop to retrieve each palindrome and test it. Your script should test each string in the list of palindromes below. Be aware there's a second list of palindromes embedded in the palindromes list....
Write a function bracket_by_len that takes a word as an input argument and returns the word...
Write a function bracket_by_len that takes a word as an input argument and returns the word bracketed to indicate its length. Words less than five characters long are bracketed with << >>, words five to ten letters long are bracketed with (* *), and words over ten characters long are bracketed with /+ +/. Your function should require the calling function to provide as the first argument, space for the result, and as the third argument, the amount of space...
In PYTHON: Write a function that receives a sentence and returns the last word of that...
In PYTHON: Write a function that receives a sentence and returns the last word of that sentence. You may assume that there is exactly one space between every two words, and that there are no other spaces at the sentence. To make the problem simpler, you may assume that the sentence contains no hyphens, and you may return the word together with punctuation at its end.
Use a switch statement to write a function that returns TRUE if a character is a...
Use a switch statement to write a function that returns TRUE if a character is a consonant and returns FALSE otherwise.
Write a boolean function that is given a binary tree and returns true if and only...
Write a boolean function that is given a binary tree and returns true if and only if the tree has an odd number of nodes. An empty tree is considered to have an even number of nodes. Notes: The function should have just one argument, a pointer to the root. No global variables may be used. No additional functions may be defined. You may not count the number of nodes.
Can you please implement this in Oracle sql Write a SELECT statement that returns one row...
Can you please implement this in Oracle sql Write a SELECT statement that returns one row for each customer that has orders with these columns: The email_address from the Customers table A count of the number of orders The total amount for each order (Hint: First, subtract the discount amount from the price. Then, multiply by the quantity.) Return only those rows where the customer has more than 1 order. Sort the result set in descending sequence by the sum...
Write function boolean isSorted(int a[], int size). The function returns true if array a is sorted...
Write function boolean isSorted(int a[], int size). The function returns true if array a is sorted in either ascend order or descend order; false otherwise. c++
a) How many ways can the letters of the word COMPUTER be arranged in a row?...
a) How many ways can the letters of the word COMPUTER be arranged in a row? b) How many ways can the letters of the word COMPUTER be arranged in a row if O and M must remain next to each other as either OM or MO? c) How many permutations of the letters COMPUTER contain P, U and T (all three of them) not to be together in any order?
Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. IN C Program.
Write a function declaration for a function that sums each row of a 2D array, where...
Write a function declaration for a function that sums each row of a 2D array, where each row size is 10. The function does not return a result. Need it in 10 minutes, please.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT