OPT.2 the secret messages exercise...any pointers?
Anything giving you trouble?
all of it :)
Have you produced any code for this exercise?
Hmm... could be done with pointers... but I don't think they mean that. Have you looked at the ascii character codes and how they represent letters?
i am doing the same PS. i wrote a code for build_coder function. i hope u find it helpful: list=[] # i created a list having ' ' and char 'a' to 'z' list.append(32) # ' ' at index 0 of list for val in range(65,91): list.append(val) # remaining char from 'a' to 'z' dict={} r_index=0 for index in range(0,27): #loop iterates through the list if(index+shift)<27: # in case index+ shift gets > 27,index gets back to 0 #print 'i+p=',(index+shift) dict[chr((list[index]))]=(chr(list[index+shift])) else: r_index=abs((index+shift)-27) dict[chr(list[index])]=chr(list[r_index]) for i in range(1,27): list[i]=list[i]+32 # for capital letters r_index=0 for index in range(0,27): if(index+shift)<27: #print 'i+p=',(index+shift) # same logic, but now list has elements 'A' to 'Z' dict[chr((list[index]))]=(chr(list[index+shift])) else: r_index=abs((index+shift)-27) dict[chr(list[index])]=chr(list[r_index]) return dict
does python support pointers?
@sahilpatel When you post code in OpenStudy, people can not copy and paste it. Try it. The code collapses. http://dpaste.com/ , http://pastebin.com/ , and https://gist.github.com/ can all easily let you share code that people can actually use.
Python itself does not use what would be called a pointer. However, it is possible to use them. Python can be used to import C functions, and thus can use pointers indirectly.
The pointers in question were in fact "tips". @matt_prichard was looking for help, not programming elements. :)
@matt_prichard I think the biggest help with this one was the modulus ( the % ). The problem is asking you to shift the numeric value of each letter in your source string. So you have to be able to do work on each of them (how would you do that?). The output is asking for you to turn ABZ, shift = 3 into DEC. How do you do that? @e.mccormick mentioned ascii - that's definitely what you want. You can convert your letter into a number, count up in the chart, and then convert back. The problem is that if you don't have a way to get from Z back around to A, you end up in weird punctuation. This is where the modulus is your friend. Say you're at Z, and Z is the 26th letter in the alphabet. You want to shift it up 3. If you add 3 you're at 29. What's the 29th letter of the alphabet? There isn't one in English. What's 29%26?
For what it's worth, this is how I solved it: https://gist.github.com/TomDeBeauchamp/5880401 Were I to go back to it, I'd write a decoder to go along with the encoder.
@TomDeBeauchamp the problem states that the first value of the sequence should be a blank space(' '). so its like ' ','a','b',..... using modulus is a wise thing to do.. kindly paste the code that includes space character before 'a'. i made a list, with ' ','a','b','c'..... as elements.. and then altered the elements in dictionary according to shift. i used somewhat complicated statement to to go from z to a... but modulus operations would make the problem more understandable.
@sahilpatel I might be looking at the wrong problem. I was looking at the Opt.2 Secret Messages for MIT 6.189 Gentle Intro to Comp Sci via Python, the last problem in this link: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/assignments/MIT6_189IAP11_hw1.pdf That one doesn't require a leading space.
I was talking about MIT 6.00SC. The problem was similar to the one you did http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/unit-2/lecture-10-hashing-and-classes/MIT6_00SCS11_ps4.pdf
Awesome. I'll have to give that one a try.
thanks TomDeBeauchamp good solution
Join our real-time social learning platform and learn together with your friends!