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

Программы на Python
Anonymous
Расчет процентов по ипотеке в Python

Сообщение Anonymous »

В настоящее время я изучаю 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 фунта стерлингов в месяц. Буду очень признателен за любую помощь, которая поможет мне разобраться в этом уравнении и понять его.

Вернуться в «Python»