A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
the answers, for pset 4, that my functions are producing are close but not close enough for my comfort to the given results. Are any of you guys experiencing the same problem? Any advice?
anonymous
 5 years ago
the answers, for pset 4, that my functions are producing are close but not close enough for my comfort to the given results. Are any of you guys experiencing the same problem? Any advice?

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Problem Set 4 ,Problem 3: I think there's an error in the given test case because it gives: [80000.000000000015, 54000.000000000015, 24000.000000000015, 4799.9999999999854, 34847.999999999985] The second last solution is way off from mine while the others are close. Maybe I'm wrong. Here's my answer for problem3: [81000.000000000015, 55860.000000000015, 26418.600000000013, 1996.2839999999851, 32036.209679999985] Is this close enough guys? Here's my code. Lemme know if I doing something wrong or how I can make my results more accurate: def postRetirement(savings, growthRates, expenses): """  savings: the initial amount of money in your savings account.  growthRate: a list of the annual percent increases in your investment account (an integer between 0 and 100).  expenses: the amount of money you plan to spend each year during retirement.  return: a list of your retirement account value at the end of each year. """ # TODO: Your code here. #this is the list which will contain the retirement account values f = [] #the value of the retirement fund at the end of the first year EndOfYearOne = savings * (1 + 0.01 * (1 + growthRates[0]))  expenses #EndOfYearOne is now f[0] f.append(EndOfYearOne) #len(growthRates) tells me the number of years the person will be retired if len(growthRates) > 1 : for i in range (1, len(growthRates)): #so that can use the previous f[] value yearVariable = i  1 #tut said I must calculate the increase of the remaining savings before subtracting expenses IncreaseInRemainingSavings = f[yearVariable] * ( 1 + (0.01 * (1 + growthRates[i]))) #calculating the value of the retirement fund at the end of the year EndOfYearValue = IncreaseInRemainingSavings  expenses f.append(EndOfYearValue) return f

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0There are reoccurring semantic bugs in calculation of savings. One here EndOfYearOne = savings * (1 + 0.01 * (1 + growthRates[0]))  expenses and the same one in for loop IncreaseInRemainingSavings = f[yearVariable] * ( 1 + (0.01 * (1 + growthRates[i]))) The idea is : newsavings = savings*1,X%, where X is growthRate of current year.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0sorry no % sign in newsavings = savings*1,X% well commented code though :)
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.