Answer:
Consider the following code.
Explanation:
Code:
Unix Terminal> cat loan_calc.py
#!/usr/local/bin/python3
import locale
from decimal import *
def main():
locale.setlocale(locale.LC_ALL, 'en_US')
print('Monthly Payment Calculator')
while True:
print('DATA ENTRY')
loan_amt = input('Loan amount: ')
loan_amt = float(loan_amt)
int_rate = input('Yearly interest rate: ')
int_rate = float(int_rate)
years = input('Years: ')
years = int(years)
mon_rate = int_rate / 12 / 100
months = years * 12
monthly_pay = loan_amt * mon_rate / ( 1 - 1/(1 + mon_rate) ** months)
monthly_pay = Decimal(monthly_pay).quantize(Decimal('.01'), rounding=ROUND_DOWN)
print()
print('FORMATTED RESULT')
print('Loan amount: %30s' %locale.currency(loan_amt))
print('Yearly interest rate: %20.2f' %int_rate + '%')
print('Number of years: %25d' %years)
print('Montly payment: %25s' %locale.currency(monthly_pay))
print()
print('Continue? (y/n): ')
choice = input().strip()
if choice.lower() == 'n':
break
if __name__=='__main__':
main()
Unix Terminal>
Code output screenshot: