Question

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 not receive credit.

Please remember that the function should be recursive!

>>> astr = 'abcdwaldowalle123waldoWALDO'
>>> print(findwaldo(astr))
4

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def findwaldo(s, index=0):
    if index < len(s):
        if s[index:].startswith('waldo'):
            return index
        else:
            return findwaldo(s, index + 1)
    return -1


astr = 'abcdwaldowalle123waldoWALDO'
print(findwaldo(astr))

Add a comment
Know the answer?
Add Answer to:
Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function...
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
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
ADVERTISEMENT