python *:'int'和'function不支持的操作数类型

时间:2019-11-11 21:09:01

标签: python

我在使用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, ".")

1 个答案:

答案 0 :(得分:1)

loanpayment是一个函数。

您需要使用参数进行调用。

在您的情况下:

loanpayment(principal, percentage, years)

完整行:

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