about | help | code help+videos | done | prefs |
Write a function compound(d, r, y) which determines the final amount of money in an account which begins with d dollars, increases at a rate of r per year, and sits for y years. Apply the function int() to turn the result of this computation into an integer, and return this integer. For example, if you start with an initial amount of d = $1000 and a rate of 5% per year (i.e. r = 0.05) then after 1 year you would have 1000*1.05 = $1050. So, compound(1000,.05,1) = 1050. In the second year, you would have 1050 * 1.05 = $1102. So, compound(1000,.05,2) = 1102. In the third year, you would have 1102 * 1.05 = 1157.1, and this means compound(1000,.05,3) = 1157, because we use int() when we return. Your answer MUST use a for loop. Do not use formulas from math courses you may have taken. compound(1000, 0.05, 1) → 1050 compound(1000, 0.05, 2) → 1102 compound(1000, 0.05, 10) → 1628 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy