def compound_interest(principle, rate, years):
if principle > 0 and rate > 0 and years > 0:
interest = 0.0
x = principle
old_principle = principle
for i in range(years):
interest = (x * rate * 1)/100
x = x + interest
comp_interest = x - old_principle
return comp_interest
else:
return(0)
compound_interest(100, 5, 2)
I did not understand the program.
Please tell me all the stps.
Why did you take for loop??
Please tell all the steps.
Compound Interest is the total amount of principal and interest in future (or future value) minus the principal amount at present (or present value). This is calculated using the above Python program. You can search on Google with the term “how to calculate compound interest” to understand better how the formula works.
Why we are taking intrest =0.0
please tell.
We are initializing the interest
variable with the value 0.0
. It’s a good practice to initialize variables.
If we do not initalize value it will not harm my program??
Please tell.
Variable initialization is not needed in Python but it is a good practice.