Compound interest program not running

def compound_interest(principle,rate,years):
i=1
while i<=years:
comp_interest=(float(principle)*float(rate)*int(years))/100
principle=float(principle+comp_interest)
i=i+1
return(comp_interest)

x=compound_interest(500,10,2)
print(x)

Hi, Ronit.

  1. Kindly check the compound interest variable called “comp_interest”, as per the instructions you need to “return(compound_interest)”.

  2. Here you have to store the old principle in a value otherwise in every iteration you will get the updated principle. (In your programme you are calculating the SI for every year).
    but compound_interest=new_principle-old_principle.
    return(compound_interest). so check the logic.

  3. You need return 0 if any of the principle, rate, years will become zero. (This is the edge case).
    else:
    return(0).

All the best!