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
But it seems like I'm repeated myself a lot in the code. Any suggestions for simplifying?
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
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.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
There are two ways I've written this:
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.
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?
Is this the point at which I fess up that I skipped the optionals? ; )
Not the answer you are looking for? Search for more explanations.
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).