Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

pdpinch Group Title

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?

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. bdean20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • 2 years ago
  2. pdpinch Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

    • 2 years ago
  3. scarson Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

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

    • 2 years ago
  4. bdean20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • 2 years ago
    • Attachments:

See more questions >>>

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.