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?
Problem 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
interesting
There 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.
sorry no % sign in newsavings = savings*1,X% well commented code though :)
Join our real-time social learning platform and learn together with your friends!