# This program prompts for information about a # loan and computes the monthly mortgage payment. # This version is decomposed into functions. # Obtains and returns needed values from the user. def read_input(): print("Monthly Mortgage Payment Calculator") loan = float(input("Loan amount? ")) years = int(input("Number of years? ")) rate = float(input("Interest rate? ")) print() return loan, years, rate # Computes and returns the monthly payment for a # loan with the given values. def compute_payment(loan, years, rate): # compute payment result n = 12 * years c = rate / 12.0 / 100.0 payment = loan * c * (1 + c) ** n / ((1 + c) ** n - 1) return payment def main(): # compute payment and report result to user loan, years, rate = read_input() payment = compute_payment(loan, years, rate) print("Monthly payment is: $", round(payment, 2)) main()