A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

care to comment on this code for problem 4?

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

    def findMaxExpenses(salary,save,preRetireGrowthRates,postRetireGrowthRates,epsilon): preretirement=nestEggVariable(salary,save,preRetireGrowthRates) index=len(preRetireGrowthRates)-1 startmoney=preretirement[index] low=0 high=startmoney counter=1 guess=startmoney/2.0 while guess<startmoney and counter<100: expenses=guess post_Retirement=postRetirement(startmoney,postRetireGrowthRates,expenses) index2=len(postRetireGrowthRates)-1 endmoney=post_Retirement[index2] if endmoney<epsilon: high=guess else: low=guess guess=(low+high)/2.0 counter+=1 print expenses, endmoney,counter if endmoney<epsilon and endmoney>-epsilon: break def nestEggVariable(salary, save, growthRates): cashpile=[] money=0 counter=0 for counter in range (0,len(growthRates)): money=money+(0.01 * growthRates[counter]) * money+(salary *(.01 *save)) cashpile.append(money) return cashpile def postRetirement(savings, growthRates, expenses): cashpile=[] money=savings counter=0 for counter in range (0,len(growthRates)): money=money+(0.01 * growthRates[counter]) * money-expenses cashpile.append(money) return cashpile def testFindMaxExpenses(): salary = 10000 save = 10 preRetireGrowthRates = [3, 4, 5, 0, 3] postRetireGrowthRates = [10, 5, 0, 5, 1] epsilon = .01 expenses = findMaxExpenses(salary, save, preRetireGrowthRates, postRetireGrowthRates, epsilon) print expenses # Output should have a value close to: # 1229.95548986

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

    pls use pastebin or dpaste.com to post code. does it work?? were you looking for style or implementation comments?

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

    It finds the answer in 20 iterations. I had a bit of a problem deciding how to make the program stop running. I made a condition that stopped the counter if the ending balance was between epsilon and -epsilon. My question is if epsilon wasn't .01 this wouldn't work as well, is there a better way to make an end condition?

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

    Don;t think so.. You have to decide how precise you want your answer to be - the more precise, the more iterations. I imagine since the problem concerns money, you could round everything to cents, multiply by one-hundred and work in integers but that is sorta the same thing.

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

    You really will need to use a code host, github, dpaste, something like that, to put up that much code. Then people can easily grab a copy, put in some print statements and play around with your script a bit.

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