Python 3.6 i need the code ready to run with adequate indentation Sample run: Th
ID: 3847302 • Letter: P
Question
Python 3.6
i need the code ready to run with adequate indentation
Sample run:
The monthly payment for a given loan pays the principal and the interest. The monthly interest is computed by multiplying the monthly interest rate and the balance (the remaining principal). The principal paid for the month is therefore the monthly payment minus the monthly interest. Write a program that lets the user enter the loan amount, number of years, and interest rate, and then displays the amortization schedule for the loan.Explanation / Answer
month = 0
totalPay = 0
monthlyInterestRate = annualInterestRate / 12.0
while month <12:
minPay = monthlyPaymentRate * balance
unpayBal = balance - minPay
totalPay += minPay
balance = unpayBal + (monthlyInterestRate * unpayBal)
month += 1
print('Month: ' + str(month))
print('Minimum monthly payment: ' + str(round(minPay,2)))
print('Remaining balance: ' + str(round(balance,2)))
print('Total paid: ' + str(round(totalPay,2)))
print(' Remaining balance: ' + str(round(balance,2)))
=---------------------------------------
initBalance = balance
monthlyInterestRate = annualInterestRate / 12.0
month = 0
minPay = 10
def calculate(month, balance, minPay, monthlyInterestRate):
while month <12:
unpaidBalance = balance - minPay
balance = unpaidBalance + (monthlyInterestRate * unpaidBalance)
month += 1
return balance
while calculate(month, balance, minPay, monthlyInterestRate) > 0:
balance = initBalance
minPay +=10
month = 0
calculate(month, balance, minPay, monthlyInterestRate)
print('Lowest Payment: ' + str(minPay))
-------------------------------
initBalance = balance
monthlyInterestRate = annualInterestRate/12.0
low = balance/12.0
high = (balance * ((1.0 + monthlyInterestRate)**12))/12.0
epsilon = 0.01
minPay = (high + low)/2.0
month = 0
def calculate(month, balance, minPay, monthlyInterestRate):
while month <12:
unpaidBalance = balance - minPay
balance = unpaidBalance + (monthlyInterestRate * unpaidBalance)
month += 1
return balance
while abs(balance) >= epsilon:
balance = initBalance
month = 0
balance = calculate(month, balance, minPay, monthlyInterestRate)
if balance > 0:
low = minPay
else:
high = minPay
minPay = (high + low)/2.0
minPay = round(minPay,2)
print('Lowest Payment: ' + str(minPay))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.