我一直在使用 python 制定摊销计划。但是,当我运行代码时,输出并没有给我正确的结果,相反,它似乎循环并打印了 360 次相同的值。下面是我写的代码。
import pandas as pd
import math
p = float(input("Amount borrowed: "))
r = float(input("Annual Interest Rate: "))
t = float(input("Payback Period in years: "))
m=(p*(r/12)*(math.pow(1+r/12,12*t)))/(math.pow(1+r/12,12*t)-1)
print()
print("Your payment will be: $"+str(m))
print()
print("Month\tStartingBalance\tInterestCharge\tPayment\tEndingBalance")
month=12*t
month=int(month)
startingBalance=p
for i in range(1,month+1):
interestCharge=r/12*startingBalance
endingBalance=startingBalance+interestCharge-m
print(str(i)+"\t$"+str(round(startingBalance,2))+"\t$"+str(round(interestCharge,2))+"\t$"+str(round(m,2))+"\t$"+str(round(endingBalance,2)))