Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The idea behind compound interest is that when interest is applied to some base

ID: 3727999 • Letter: T

Question

The idea behind compound interest is that when interest is applied to some base amount regularly over a given time period, each interest payment increases the base amount, so that the next interest payment is calculated against the increased base amount. For example, say you have a $1000 savings bond that matures in 10 years. The first year it earns $100 interest (10% of $1000). This interest is added to the base amount (S 1000 + S 100-> SI 100). The second year the bond earns $110 interest (10% of si 100), and the base increases to S1210 (S1100 + SI 10-> SI 210); and so on. After 10 years, the bond grows to $2593.74. Implement the following function using a while loop. Provide appropriate assertions. def compound(base, percent, time): Determines total cost of a loan. Preconditions: base - principle amount to apply interest to (float 0) percent percent change applied to base (float 0) time time period for change (int + 0) Postconditions: returns final - total amount of a principle with compound interest added.

Explanation / Answer

def compound(base,percent,time):

  assert 0 < base
assert 0 < percent
assert 0 < time
while(time!=0): //runs the loop till time = 0
base = base + base*percent/100 //adds interest to the base for each year
time = time - 1 //decrement time value
return round(base,2) // return total rounded to two decimal places

base = float(input("Enter base"))
percent = float(input("Enter interest percent"))
time = int(input("Enter time in years"))
print(compound(base,percent,time))