A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

Just finished Problem Set 4. Everything seemed to run properly, and I can't see any faults with the code. Can you guys/gals give this a quick look at and give me any criticisms or thoughts on things I could have done differently are possibly bugs I overlooked? Thanks! https://gist.github.com/1628010

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

    did you post a link to your code?

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

    Yes, it's right below my the paragraph. Now that I'm looking at it, the link is kind of hard to see due to the background. Let me repost it here: https://gist.github.com/1628010

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    it looks ok.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hi, would you mind explaining what "account[year-1]" is doing in your else statement in the testNestEggFixed function please?

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    nestEggFixed not testNestEggFixed. Sorry.

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    That was prior to me figuring out that I can access the last element in a list with account[-1]. In that particular case, I knew exactly how many elements was in the list, and found the last element by calculating the number of years-1. In other words, I learned a better way midway through the problem set to find the last element in a list, and just didn't go back to change that particular piece of code.

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks. It wasn't a criticism. I had just started that problem and I wasn't sure how to do that part and didn't understand what the code was actually doing. It all makes sense now.

  8. maitre_kaio
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Just two little things you may improve in your code, the goal is too improve readability and to keep maintenance easy to do: 1. In nestEggFixed for example, you are evaluating several times the expression: salary * save * 0.01 You may evaluate it just one time and keep the result in a variable: newContribution = salary * save * 0.01 This will make the code more concise. Another nice consequence: let's say that later you want to change the way this is calculated (maybe the now save is already a percentage). Instead of changing the formula everywhere, which is error prone, you do it in one single place. 2. in the findMaxExpenses while loop, you evaluate the variables guess and postRetireSavings before the loop and inside the loop. For the same reasons than before, I think it's better to do it just one time, in the while loop. If Python had a 'do...while' construct it would be very easy, but sadly it doesn't as far as I know. So to do this you have to slightly change the code. As I said , these are little things, that means your code is pretty good :)

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hey Matire, Thanks for the feedback! I went back and made same of the changes you talked about and redid some of the code. https://gist.github.com/1628010 Now, I did something with some of the functions that I'm not sure is good practice. I was able to cut some code out by popping the last element in a list returned by nestEggVariables by directly invoking it on the function itself. While this does save me having to do a savings = savings[-1] kind of thing, I was wondering if something like that is considered kosher, so to speak. I ask this because many moons ago I use to mess around with C, and the one thing that working with C left me was that all because there's a million ways to skin a cat, there's just some ways you shouldn't.

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