## Loan problem
def mon_pay( prin, an_i, dur ) :
n = dur * 12
r = (an_i/100)/12
numerator = r*(1+r)**n
dinominator = (1+r)**n - 1
if an_i == 0 :
mon_pay = prin/n
else :
mon_pay = prin * (numerator/dinominator)
return mon_pay
def rem_pay( prin, an_i, dur, num_pay) :
n = (dur * 12)
r = (an_i/100)/12
numerator = ((1+r)**n - (1+r)**num_pay)
dinominator = ((1+r)**n - 1)
if an_i == 0 :
rem_pay = (prin * (1-num_pay/n))
else :
rem_pay = (prin * (numerator/dinominator))
return rem_pay
prin = float ( input ("Enter the Principal of loan: "))
an_i = float ( input ("Enter the annual interest rate: "))
dur = int (input ("Enter the duration of loan: "))
mon_pay = mon_pay(prin, an_i, dur)
print("LOAN AMOUNT:",prin,"INTEREST RATE(PERCENT):",an_i)
print("DURATION(YEARS):",dur,"MONTHLY PAYMENT:",int(mon_pay))
for yr in range (1, dur+1) :
total_pay = mon_pay*12*yr
_yr = yr*12
rem_pay = rem_pay(prin, an_i, dur, _yr)
print("YEAR:",yr,"BALANCE:",rem_pay//1,"TOTAL PAYMENT",total_pay//1)
i have given my code above, it's a simple problem to calculate loan details( i am just just studying python and this is an assignment). When i run it i get this:
Enter the Principal of loan: 1000
Enter the annual interest rate: 10
Enter the duration of loan: 5
LOAN AMOUNT: 1000.0 INTEREST RATE(PERCENT): 10.0
DURATION(YEARS): 5 MONTHLY PAYMENT: 21
YEAR: 1 BALANCE: 837.0 TOTAL PAYMENT 254.0
Traceback (most recent call last):
File "C:/Python34/Zsample9(loan_prob).py", line 35, in <module>
rem_pay = rem_pay(prin, an_i, dur, _yr)
TypeError: 'float' object is not callable
the function
rem_pay = rem_pay(prin, an_i, dur, _yr)
runs the first time, but the second time it gives the mentioned error I can't see why, Anybody please help!
Don't use same name for variable and function.
In this case
rem_pay
is used both as function and float variable.