Apr-02-2019, 08:56 PM
I am writing a program that calculates the remaining loan after a certain number of years n.
The initial borrowed amount is called 'balance' in this code and the formula after n years is
balance(year n)=balance (year n-1)*(r/100 +1) + A where A is a constant.
If for example this year I borrowed 1000000, the remaining balance next year would be 10000(r/100 +1) + A
and the year after would be whatever I get from this calculation plugged into the formula.
This is the code that I obtained and I am always getting 0.
I am also not sure how to arrange the code to find out how much loan I have left after n years (this n can be any integer)
The initial borrowed amount is called 'balance' in this code and the formula after n years is
balance(year n)=balance (year n-1)*(r/100 +1) + A where A is a constant.
If for example this year I borrowed 1000000, the remaining balance next year would be 10000(r/100 +1) + A
and the year after would be whatever I get from this calculation plugged into the formula.
This is the code that I obtained and I am always getting 0.
I am also not sure how to arrange the code to find out how much loan I have left after n years (this n can be any integer)
def f(balance,r,n,A): r=13 A=1000 balance=1000000 return (balance)*(r/100 +1) - A while balance>0: balance-=f(balance,r,n,A) balance=round(balance,2) if balance<0: balance=0 print(balance)