簡體   English   中英

python *: 'int' 和 'function 不支持的操作數類型

[英]python unsupported operand type(s) for *: 'int' and 'function

我的 python 遇到問題,因為它一直向我返回此錯誤代碼

 total_amount = loanpayment * years * 12
TypeError: unsupported operand type(s) for *: 'function' and 'int'
def loanpayment(principal, percentage, years):
    i = (percentage/100)/12
    n = years * 12
    P = principal
    loanpayment = (i*principal*((1+i)**n))/(((1+i)**n)-1)
    return loanpayment

principal = int(input(""))
percentage = float(input(""))
years = int(input(""))
num_payments = years * 12

total_amount = loanpayment * years * 12

print("Monthly payment : {}".format(loanpayment(principal,percentage,years)))
print("Total interest paid", interest, ".")

貸款支付是loanpayment

你需要用參數調用它。

在你的情況下:

loanpayment(principal, percentage, years)

整行:

total_amount =  loanpayment(principal, percentage, years) * years * 12

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM