Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Judeson Group Title

Hello guys,I'm working in problem set 4,everytime I rum this function I find 0. def find_best_shift(wordlist, text): max_num_real_words = 0 best_shift = 0 for shift in range(27): shifted_text = apply_shift(text, shift) potential_words = shifted_text.split() num_real_words = 0 for word in potential_words: if is_word(wordlist, word): num_real_words += 1 if num_real_words > max_num_real_words: max_num_real_words = num_real_words best_shift = shift return best_shift Help

  • 10 months ago
  • 10 months ago

  • This Question is Closed
  1. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    looks reasonable, maybe try some print statements like this http://dpaste.com/1383878/

    • 10 months ago
  2. Judeson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Hi , it still don't work. Traceback (most recent call last): File "<pyshell#125>", line 1, in <module> find_best_shift(wordlist, "oryh") File "/Users/Avatar/Documents/problem 4", line 135, in find_best_shift print 'shift: [] words: []'.format(shift, potential_words) AttributeError: 'str' object has no attribute 'format'

    • 10 months ago
  3. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    how 'bout this http://dpaste.com/1384625/

    • 10 months ago
  4. Judeson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    s = apply_shift("love", 3) >>> s ' ORYH' >>> find_best_shift(wordlist, s) shift: 0 words: ['ORYH'] 0 Samething than before!

    • 10 months ago
  5. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    what could be wrong? what did the print statement print? did it print what you expected it to print? did it print what it should have printed? how many times did it print? how many times should it have printed? what other steps have you taken to find the problem and what were the results? print statements can tell you a lot about how your code is executing

    • 10 months ago
  6. Judeson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I reallt don't know what could be wrong with my function.The "print statement " print teh shift wich were 0 and the ecoded letter. It should print a number != to 0,it should print it one time and it printed exactly one time.

    • 10 months ago
  7. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    is the print statement in a loop? how many times should the loop execute?

    • 10 months ago
  8. Judeson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    The print statement iss not in a loop.

    • 10 months ago
  9. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    did you write the function? the print statement is in a loop. ``` >>> >>> for shift in range(27): print shift 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 >>> ``` http://docs.python.org/2.7/tutorial/controlflow.html#for-statements

    • 10 months ago
  10. Judeson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I wrote a print statement. def find_best_shift(wordlist, text): max_num_real_words = 0 best_shift = 0 for shift in range(27): shifted_text = apply_shift(text, shift) potential_words = shifted_text.split() print 'shift:', shift, ' words:', potential_words num_real_words = 0 for word in potential_words: if is_word(wordlist, word): num_real_words += 1 if num_real_words > max_num_real_words: max_num_real_words = num_real_words best_shift = shift return best_shift

    • 10 months ago
  11. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ok ... when you call the function, how many times does it print? how many times should it print?

    • 10 months ago
  12. voodoo_73 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I'd suggest to use print stmt: print shifted_text and see the output of apply_shift proc

    • 10 months ago
  13. Judeson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I try all it still don't work. So do you have an idea about how can I import feedparser?

    • 10 months ago
  14. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    different topic, start a new thread. if you want your best_shift function to work you need to examine the position of your return statement. did you write the function you posted?

    • 10 months ago
  15. Judeson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thank you I will try

    • 10 months ago
  16. voodoo_73 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    bwCA - exactly, problem with 'return' :) silly :)

    • 10 months ago
  17. Judeson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I change my return statement place it still doesn't work

    • 10 months ago
  18. voodoo_73 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    well, do not change the place :) are you certain it is at the very end of your def?

    • 10 months ago
    • Attachments:

See more questions >>>

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.