A community for students.
Here's the question you clicked on:
 0 viewing
Aslander
 4 years ago
PS4.3: Ok I have this odd problem...the post retirement fund...my first three amounts add up, but then amount 4, 5 do not match. I cannot find the problem with my algorithm...any thoughts?
Aslander
 4 years ago
PS4.3: Ok I have this odd problem...the post retirement fund...my first three amounts add up, but then amount 4, 5 do not match. I cannot find the problem with my algorithm...any thoughts?

This Question is Closed

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0My code is this: def postretirement(savings, growthrates,expenses): savingsrecord = [] for i in range(len(growthrates)): fund = savings + float(savings*growthrates[i])  expenses savingsrecord.append(fund) savings = fund print "SavingsRecord", savingsrecord

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0The amounts that were specified are this: [80000.000000000015, 54000.000000000015, 24000.000000000015, 4799.9999999999854, 34847.999999999985] My last two records are slightly different.

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0And are returned as this: SavingsRecord [80000.0, 54000.0, 24000.0, 4800.0, 39600.0]

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0Ok I reworked my code a bit, but I am still off... Results: SavingsRecord [80000.0, 54000.0, 24000.0, 4800.0, 34800.0] def postretirement(savings, growthrates,expenses): savingsrecord = [] for i in range(len(growthrates)): if savings > 0: fund = savings + float(savings*growthrates[i])  expenses savingsrecord.append(fund) savings = fund else: fund = float(savings*growthrates[i])  expenses savingsrecord.append(fund) print "SavingsRecord", savingsrecord Ideas?

Keen
 4 years ago
Best ResponseYou've already chosen the best response.0"savings*growthrates[i]" This should be savings*0.01*growthrates[i] to convert the growthrates to percentages. I too am having issues on this problem. I'll report what I find. My current output is: [80000.00000000001, 54000.000000000015, 20000.000000000015, 1964.9999999999818, 38563.70919999998]

Keen
 4 years ago
Best ResponseYou've already chosen the best response.0This is my current code. Still baffled. #Initialize result with (savings * (1 + .01 * growthRates[0])) in each index, with #result's length being equal to the number of years of growth rates. result = [savings * (1 + .01 * growthRates[0])  expenses] * len(growthRates) for j in range(1, len(growthRates)+1): for i in range(j, len(growthRates)): result[i] = result[i] * (1 + .01 * growthRates[i])  expenses return result

joelrob
 4 years ago
Best ResponseYou've already chosen the best response.0i believe you are missing compounding.try f=[] f.append(savings) for i in range(len(growthRates)): f.append (f[i]*(1+.01*growthRates[i])expenses) del f[0] return f

Keen
 4 years ago
Best ResponseYou've already chosen the best response.0I'm using the same code I used for the earlier steps in the assignment, so I shouldn't have compounding issues. I would have gotten the wrong answers earlier in the problem set. I think we're having issues with error propagation. I added some prints to my code to track values of variables: result[i] * (1 + .01 * growthRates[i])  expenses = 20000.0 result[i] = 50000.0 growthrates[i] = 0 But if I type the values of those variables right into the interpreter: >>> 50000*(1+.01*1)  30000 20500.0

Keen
 4 years ago
Best ResponseYou've already chosen the best response.0Err, nevermind. I dunno how I missed that 0 doesn't equal 1. Derp derp.

Keen
 4 years ago
Best ResponseYou've already chosen the best response.0Yeah, now I've got it working. My previous method was failing to properly multiply against previous iterations. I like your use of append to iterate, very slick.

Keen
 4 years ago
Best ResponseYou've already chosen the best response.0Isn't this code: f=[] f.append(savings) the same as: f = [savings]

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0I did not add the "1+...." into my algorithm...I will recode that part and see what I get...

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0Hey  I changed my code and got it to work perfectly  thanks for all your help!

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0If you want to take a look at the new trial and compare the results: def postretirement(savings, growthrates,expenses): """Growthrates as a list of percentages ex. (0.01 for 10%)""" savingsrecord = [] for i in range(len(growthrates)): if savings > 0: #fund = savings + float(savings*growthrates[i])  expenses fund = float(savings*(1+(0.01*growthrates[i])))  expenses savingsrecord.append(fund) savings = fund print "Expenses", expenses else: fund = float(savings*(1+0.01*growthrates[i]))  expenses savingsrecord.append(fund) savings = fund print "SavingsRecord", savingsrecord return savingsrecord

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0The commented out code was the original equation I used...don't know why I missed the 1+, but now its there on the line just below. Thanks again.

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0Of course, this: """Growthrates as a list of percentages ex. (0.01 for 10%)""" would no longer apply either, as I changed the code to accept just the raw percentage, rather than floating points.

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0Isn't this code: f=[] f.append(savings) the same as: f = [savings] You are making a list of a list. So, if you take as an example, savings = [1,2,3,4,5] then f =[savings] would return [[1,2,3,4,5]]. I don't know if that would matter, unless you append savings or f with another list, because then you would have to be careful about indexes. Example: Append savings with 7, then f with 8. Notice the difference? savings = [1,2,3,4,5,6,7] f = [[1,2,3,4,5,6,7],8] So, savings[1] which is not the same as f[1].

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0Savings[1] = 2 f[1] = 8

Keen
 4 years ago
Best ResponseYou've already chosen the best response.0> You are making a list of a list. So, if you take as an example, > savings = [1,2,3,4,5] Except savings is just an int for that problem, not a list.

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0If you simply need an int, then the original question: is f.append(savings) the same as f = [savings], is not really relevant, since both involve lists. If you just need an int, then use variables without list functions.
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.