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....
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.
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.
Use the Design Recipe to write a function count_vowels, which consumes a string and returns the...
Use the Design Recipe to write a function count_vowels, which consumes a string and returns the number of vowels in that string. For these purposes, the vowels are a, e, i, o, and u, but never y. Include a Docstring! Note: Count both upper and lowercase vowels! Write 3 assert_equal statements to test your function.
(C++ ) ·In “recursive.cpp”, write a recursive function minDoub() which: ·returns the address of the smallest...
(C++ ) ·In “recursive.cpp”, write a recursive function minDoub() which: ·returns the address of the smallest value in the array. If the array is empty, return the “end” pointer ·and takes as parameters: (1)   a pointer to double. The pointer is the address of the start of an array, (2)   the “end” pointer to the address after the array (3)   and the address of the smallest value seen so far ·Write main() to test this function – try a case where the array...
Write a function which receives a list and returns a number. In the list, all numbers...
Write a function which receives a list and returns a number. In the list, all numbers have been repeated twice except one number that is repeated once. The function should return the number that is repeated once and return it.write a python program for this question. use main function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT