Question

findWordCrossIndex(horizontalWord, verticalWord) This function finds and returns the index in the string "horizontalWord" of the first...

findWordCrossIndex(horizontalWord, verticalWord) This function finds and returns the index in the string "horizontalWord" of the first character that also appears in the string "verticalWord". If the two parameters do not contain any of the same characters, it returns -1. Code using python.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

EXPLANATION:

Step 1:Iterate through each value in horizontalWord and check whether it is there in verticalWord if found the return that index, Else passes through all the values if anything is not found return -1." In" is used to check whether data is in the other word or not

Step 2: call the function with different parameters to check the output

SOLUTION:

##define the function that takes two parameters
def findWordCrossIndex(horizontalWord,verticalWord):
##iterate through each letter in horizontalWord and check for matching in verticalWord
##if matching found to return the index
for i in range(len(horizontalWord)):
if (horizontalWord[i] in verticalWord):
return i
##if any value is returned it will exit from the program by returning that index if not the remaining statements will be\
##executed i.e -1 is returned if not found
##if any value is not returned then only this will execute
return -1


##call the function for debugging
print(findWordCrossIndex("hello","abcd"))

CODE IMAGE:

OUTPUT:

-1 since no matching found

Add a comment
Know the answer?
Add Answer to:
findWordCrossIndex(horizontalWord, verticalWord) This function finds and returns the index in the string "horizontalWord" of the first...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function...

    Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...

  • Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that...

    Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that takes an input string, and returns a the unscrambled version of the argument. To unscramble the string: When the string has an odd number of characters, middle character is the first character in the unscrambled result Pairs of remaining characters are added to the result, proceeding left to right from inner-most to outer-most characters. Example Call: unscramble('3cis1') Expected result: ics31 Example Call: unscramble('ocicssol') Expected...

  • Write a Python function called more() that takes three string inputs and outputs a string Formally,...

    Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...

  • 11. The str_word_count() function returns the number of digits in a string. T/F [?] 12. The...

    11. The str_word_count() function returns the number of digits in a string. T/F [?] 12. The term parsing refers to the act of dividing a string into logical component substrings or tokens. T/F [?] 13. The strpos() function performs a case-sensitive search for specified characters in a string and returns the position of the first occurrence of a substring within a string. T/F [?] 14. The strchr() function or strrchr() function return a substring from the specified characters to the...

  • 1. Write a function called ordinal_sum that accepts a string argument and returns the sum of...

    1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal. 2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable...

  • 2) Write a function stringManip that takes in a character string and returns a character string...

    2) Write a function stringManip that takes in a character string and returns a character string following these rules: a) any vowel (a, e, i, o, u) is replaced by the character '&' b) any numeric character has 1 added to it (if it was 9, it becomes O instead) (str2num() is useful here) c) all lowercase characters become uppercase d) replace the final character with '!' e) append the length of the string before this step to the end...

  • 8.4 in python function that checks whether a string is a valid password. Suppose the pas...

    8.4 in python function that checks whether a string is a valid password. Suppose the pas rules are as follows: . A password must have at least eight characters - A password must consist of only letters and digits. ■ A password must contain at least two digits. Write a program that prompts the user to enter a password and displays valid password if the rules are followed or invalid password otherwise (Occurrences of a specified character) Write a function...

  • write a Node.js function searchString() that receives three parameters: a positive integer in the range of...

    write a Node.js function searchString() that receives three parameters: a positive integer in the range of 1 to 20, a target string of characters of that length, and a single character. It then checks whether or not the target string contains the given character. If it does, this function returns the index of the target string where the character is first found. Otherwise, it returns -1.

  • Python Language Problems 1. isdigit() A. Returns True if this string is just a digit. B....

    Python Language Problems 1. isdigit() A. Returns True if this string is just a digit. B. Returns True if this string contains only number characters. C. Return True if this string has at least one number character. D. is not a valid function. 2. Pick the most accurate interpretation for the if construct: if letter in words: print("Got it") A. If the character letter existed in the string words, it prints "Got it". B. It traverse through the string words,...

  • Write a function named words_in_both that takes two strings as parameters and returns a set of...

    Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can assume all characters are letters or spaces. Capitalization shouldn't matter: "to", "To", "tO", and "TO" should all count as the same word. The words in the set should be all lower-case. For example, if one string contains "To", and the other string contains "TO", then the set should contain "to". The file must be named: words_in_both.py...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT