A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • one year ago

Right, so I'm working on Problem Set 4, and have found myself stuck on the 'find best shift' part. I've gotten everything before it, I think, but right now every time my recommended shift is '26'. Here's my current code for it: ctr = -1 Yaaay = False while ctr<=25 and Yaaay == False: ctr +=1 apply_coder(text, build_decoder(ctr)) current = 0 spacelist = [-1] while current<len(text): if text[current] == ' ': spacelist.append(current) current +=1 k = 1 good

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

    So the code didn't get completely through. Here's the actual code: ctr = -1 Yaaay = False while ctr<=25 and Yaaay == False: ctr +=1 apply_coder(text, build_decoder(ctr)) current = 0 spacelist = [-1] while current<len(text): if text[current] == ' ': spacelist.append(current) current +=1 k = 1 good = True if len(spacelist)>1: while k<len(spacelist) and good == True: Word = text[spacelist[k-1]+1:spacelist[k]] if Word in wordlist: good = True else: good = False k +=1 else: if text in wordlist: good = True else: good = False Yaaay = good return ctr

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

    I've returned your function below, I've put in a bunch of print statements that show some of the values as your loop walks through each value. Once you see the values, try uncommenting a block of code I put in that is commented out by 4 hash tags: ### TODO ctr = -1 Yaaay = False while ctr<=25 and Yaaay == False: ctr += 1 ## print "text before apply_coder = ", text ## apply_coder(text, build_decoder(ctr)) ## function is changing text, but not assigning that value to any variable codedText = apply_coder(text, build_decoder(ctr)) ## try this #### print "text after apply_coder = ", text #### words = codedText.split() #### print 'words = ', words, 'ctr =', ctr #### for word in words: #### if is_word(wordlist, word): #### print True current = 0 spacelist = [-1] ## print "len(text) = ", len(text) while current<len(text): if codedText[current] == ' ': ## print "text[current] = ", text[current] spacelist.append(current) current +=1 k = 1 good = True ## print 'spacelist = ', spacelist if len(spacelist)>1: while k<len(spacelist) and good == True: # will always only go through once, good will always be set to False Word = codedText[spacelist[k-1]+1:spacelist[k]] print "k = ", k, "codedText = ", codedText, " codedText[spacelist[k-1]+1:spacelist[k]] = ", codedText[spacelist[k-1]+1:spacelist[k]] if Word in wordlist: ## when evaluating Word, this doesn't account for any punctuation. print "word is in wordlist" good = True else: print 'good is false, ', Word, 'is not a word.' good = False k += 1 else: if codedText in wordlist: print "good = True" good = True else: print 'good is false, ', codedText, 'is not a word.' good = False Yaaay = good print 'returning, ctr = ', ctr, '. Yaaay = ', Yaaay return ctr

  3. 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.