A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • one year ago

I'm trying to complete problem set 4 and the find_best_shifts_rec function. It works for the most part, but for some reason, it is unable to completely decode the fable. One of the recursive calls fails at the same spot in the fable. Any help would be appreciated Here is my code: def find_best_shifts_rec(wordlist, text, start): for shift in range(27): s = text[:start] + apply_shift(text[start:], shift) space = s.find(" ", start) if space > 0 and is_word(wordlist, s[start:space]): return [(start, shift)] + find_best_shifts_rec(wordlist, s, space + 1) if space < 0 and is_word(wordlist, s[start:]): return [(start, shift)] if space < 0 and not is_word(wordlist, s[start:]): continue

  • This Question is Closed
  1. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    No comment on whether this'll solve anything (I'm actually trying to figure out how to do this question myself), but shouldn't space be <= 0?

  2. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Well, I thought about putting that in there. But then I realized: space = s.find(" ", start) the above variable actually holds an index to where the space is found. So if a space is found at index 0, the text won't be a word, and so the three 'if' statements should evaluate to false in order to move onto the next shift (or integer in the for loop). Thanks for the help though.

  3. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    If you know where in the fable the program is failing, manually step through your code with the data that it's working with at the time.

  4. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks, it looks like the function is finding a shift that creates a word, but it's the wrong shift. Back to the drawing board.

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.