A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
care to comment on this code for problem 4?
anonymous
 5 years ago
care to comment on this code for problem 4?

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0def 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]) * moneyexpenses 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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0pls use pastebin or dpaste.com to post code. does it work?? were you looking for style or implementation comments?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0It 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?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Don;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 onehundred and work in integers but that is sorta the same thing.

carlsmith
 5 years ago
Best ResponseYou've already chosen the best response.0You 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.
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.