Ask your own question, for FREE!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW) 15 Online
OpenStudy (pdpinch):

I managed to get the cipher script working in optional exercise 2 in 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 https://gist.github.com/3802851 But it seems like I'm repeated myself a lot in the code. Any suggestions for simplifying?

OpenStudy (anonymous):

There are two ways I've written this: http://pastebin.com/Bt0FkzGw With the first, I rewrote it completely myself with the goal of writing it with no other function dependencies than ord and chr, while still being readable With the second, I used your code and moved the repeated code into a function. Read over each and see which style you like best.

OpenStudy (pdpinch):

Wow, thatnks, there's a lot of food for though there. I was a little hamstrung because I haven't gotten to the part of the course on functions yet. I actually really like the fist version you did, because I think the code is much more readable. The if... In construct seems really useful, and probably would have made some of my earlier programs easier to read. I've never seen %= before. Is that a common operator?

OpenStudy (anonymous):

Is this the point at which I fess up that I skipped the optionals? ; )

OpenStudy (anonymous):

I don't know any languages that have += that don't have %=, if that's what you mean. Either way, %= isn't something I use often. Usually when you want to mod something, you can put the mod somewhere else (just add it to the end of another line).

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!