Расчет процентов по ипотеке в Python

В настоящее время я изучаю Python через видеоурок на YouTube, и натолкнулся на формулу, которую я не могу понять, поскольку мне ничего не кажется правильным. Основная концепция упражнения заключается в создании ипотечного калькулятора, который просит пользователя ввести 3 элемента информации: сумму кредита, процентную ставку и срок кредита (годы)

затем он рассчитывает ежемесячные платежи пользователю. вот мой код:

__author__ = 'Rick'
# This program calculates monthly repayments on an interest rate loan/mortgage.

loanAmount = input("How much do you want to borrow? \n")
interestRate = input("What is the interest rate on your loan? \n")
repaymentLength = input("How many years to repay your loan? \n")

#converting the string input variables to float
loanAmount = float(loanAmount)
interestRate = float(interestRate)
repaymentLength = float(repaymentLength)

#working out the interest rate to a decimal number
interestCalculation = interestRate / 100

print(interestRate)
print(interestCalculation)

#working out the number of payments over the course of the loan period.
numberOfPayments = repaymentLength*12

#Formula
#M = L[i(1+i)n] / [(1+i)n-1]

#   * M = Monthly Payment (what were trying to find out)
#   * L = Loan Amount (loanAmount)
#   * I = Interest Rate (for an interest rate of 5%, i = 0.05 (interestCalculation)
#   * N = Number of Payments (repaymentLength)

monthlyRepaymentCost = loanAmount * interestCalculation * (1+interestCalculation) * numberOfPayments / ((1+interestCalculation) * numberOfPayments - 1)
#THIS IS FROM ANOTHER BIT OF CODE THAT IS SUPPOSE TO BE RIGHT BUT ISNT---
# repaymentCost = loanAmount * interestRate * (1+ interestRate) * numberOfPayments  / ((1 + interestRate) * numberOfPayments -1)

#working out the total cost of the repayment over the full term of the loan
totalCharge = (monthlyRepaymentCost * numberOfPayments) - loanAmount


print("You want to borrow £" + str(loanAmount) + " over " + str(repaymentLength) + " years, with an interest rate of " + str(interestRate) + "%!")

print("Your monthly repayment will be £" + str(monthlyRepaymentCost))

print("Your monthly repayment will be £%.2f " % monthlyRepaymentCost)

print("The total charge on this loan will be £%.2f !" % totalCharge)

Все работает, но ценность, которую он выбрасывает в конце, совершенно неверна ... кредит в 100 фунтов стерлингов с процентной ставкой 10% в течение 1 года не должен заставлять меня платить 0,83 фунта в месяц. Буду очень признателен за любую помощь, чтобы разобраться в этом уравнении, чтобы помочь мне понять.

Ответы на вопрос(6)

Ваш ответ на вопрос