35
loading...
This website collects cookies to deliver better user experience
class Mortgage:
def __init__(self):
self.principal = pyip.inputFloat("Type loan's principal: ")
self.interest_rate = pyip.inputFloat("Type yearly interest rate: ")
self.interest_rate = self.interest_rate / 100 / 12 # yearly percentage rate divided by 12
def monthly_amount(self):
self.yearly_term = pyip.inputInt("Type yearly term: ")
self.yearly_term *= 12 #number of monthly payments
payment = ((self.interest_rate * self.principal) / ((1 - ((1 + (self.interest_rate)) ** (-self.yearly_term)))))
return f'Monthly amount payment for ${self.principal:6.2f} in {self.yearly_term} months: ${payment:6.2f}'
def term(self):
self.payment = pyip.inputFloat("Type the monthly amount: $")
term = 0
balance = self.principal
while balance > 0:
balance = balance + (self.interest_rate * balance) - self.payment
term += 1
return f"The loan's principal ${self.principal} would take {term} months to be paid."
mortgage = Mortgage()
print("Choose '1' for monthly amount, '2' for loan's term(years), or '3' to exit.")
choice = pyip.inputMenu(choices=['monthly amount', "loan's term", "quit"], numbered=True)
print('Your choice:', choice)
if choice == 'monthly amount':
print('=' * (len(mes) + 10))
print(mortgage.monthly_amount())
print('=' * (len(mes) + 10))
elif choice == "loan's term":
print('=' * (len(mes) + 10))
print(mortgage.term())
print('=' * (len(mes) + 10))