[英]TypeError: 'int' object is not callable total_interest = num_payments(years * 12) * loanpayment(principal, percentage, years)
[英]Int object is not callable in Investment (interest) Calculator
我正在嘗試打印我的復利公式的答案,但它一直說我的 integer 不可調用。
#Ask user what P equals
P = int(input('What is the initial investment? '))
#Ask user for the meaning of r
r = int(input('What is the annual nominal interest rate? '))
#Ask user for meaning of n
n = int(input('How many times will your interest compound this year? '))
#Ask user for t
t = int(input('How many years are you planning to invest? '))
#Compute compounding interest formula
A = P(1+(r/n))**nt
#convert line 30 into a String
A = str(A)
#Print statement
print('You will have $',A, "in", t, 'years.')
在這條線上
A = P(1+(r/n))**nt
我假設你打算做乘法?
A = P*(1+(r/n))**(n*t)
另請注意,您需要//
執行“真正除法”而不是 integer 除法
r // n
首先你忘了做乘法,結果出錯了。
這是正確的方法
A = P*(1+(r/n))**(n*t)
或者
除了使用**
你還可以使用 python 的內置 function 稱為 pow
pow() function 返回 x 的 y 次冪 (x^y)。
A = P * (pow((1 + r / n),(n*t)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.