anonymous
  • anonymous
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
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
looks reasonable, maybe try some print statements like this http://dpaste.com/1383878/
anonymous
  • anonymous
Hi , it still don't work. Traceback (most recent call last): File "", line 1, in 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'
anonymous
  • anonymous
how 'bout this http://dpaste.com/1384625/

Looking for something else?

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

More answers

anonymous
  • anonymous
s = apply_shift("love", 3) >>> s ' ORYH' >>> find_best_shift(wordlist, s) shift: 0 words: ['ORYH'] 0 Samething than before!
anonymous
  • anonymous
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
anonymous
  • anonymous
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.
anonymous
  • anonymous
is the print statement in a loop? how many times should the loop execute?
anonymous
  • anonymous
The print statement iss not in a loop.
anonymous
  • anonymous
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
anonymous
  • anonymous
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
anonymous
  • anonymous
ok ... when you call the function, how many times does it print? how many times should it print?
anonymous
  • anonymous
I'd suggest to use print stmt: print shifted_text and see the output of apply_shift proc
anonymous
  • anonymous
I try all it still don't work. So do you have an idea about how can I import feedparser?
anonymous
  • anonymous
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?
anonymous
  • anonymous
Thank you I will try
anonymous
  • anonymous
bwCA - exactly, problem with 'return' :) silly :)
anonymous
  • anonymous
I change my return statement place it still doesn't work
anonymous
  • anonymous
well, do not change the place :) are you certain it is at the very end of your def?

Looking for something else?

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