In: Computer Science
In python please
6.12 Mortgage Example
A mortgage company is interested in automating their decision-making process.
As part of this automation, they are looking for a software that takes a set of information from each customer and identify
1) if a customer is eligible to apply for a mortgage
2) if a customer is qualified to get the mortgage of the requested amount,
eligibility criteria:
1. the applicant should be 19 or over 19 years old
2. the applicant should be the resident of that country (in the beginning assume that the applicant needs to be a resident of U.S.)
qualification criteria
1. the applicant should be eligible
2. the difference between the applicant's monthly income and applicant's monthly expenses should be greater than the mortgage monthly payments
Considering the code in the template, complete the code so that it prints; 1) if the user is eligible 2) the amount of monthly mortgage payment for the requested amount of mortgage with a specific interest rate taken from input and specific amount of time (in years) to pay off the mortgage, and 3) if the used is qualified
Hint: use this formula to calculate the monthly mortgage payment: (RequestedMortgageAmount + (RequestedMortgageAmount * overallinterestrate)) / (years * 12)
please consider 15%, 20% and 24% overall interest rate for pay offs in 10, 15, and 30 years, respectively. Round down the monthly mortgage payment using int() function.
Fix the mortgagemonthlypayment function and then call it in the main program with appropriate inputs.
Given code:
# we define four functions; eligible(),
difference_btw_incomeAndexpense(), mortgae_monthly_payment() and
qualify()
# reminder: each function is like a template and it does not run
unless we call it with appropriate set of input values
# This function takes applicant's age and country of residence
and return a boolean variable;if True meaning that the applicant is
eligible
def eligible(age, country_of_residence):
elig = False
if (age >= 19) and (country_of_residence == 'USA'):
elig = True
return elig
# This function takes the family income value and all expenses and
calculate the difference btw them and return the difference
def difference_btw_incomeAndexpense(family_income, loan_payments,
educations_payment, groceryAndfood, others):
diff = family_income - (loan_payments + educations_payment +
groceryAndfood + others)
return diff
# This function takes the user requested amount of mortgage and
applies an interest rate to it and calculates the monthly payment
amount
# This function applies 20% overall interest rate over 15
years
# you can make changes to this function and make it closer to what
happens in reality. How ????????????????????
#def mortgage_monthly_payment(RequestedMortgageAmount):
# m_p = (RequestedMortgageAmount + (RequestedMortgageAmount * 0.2))
/ (15 * 12)
# return m_p
def mortgage_monthly_payment(RequestedMortgageAmount,
years):
#### FIX ME
# This function takes the output of the last two function and
the amount of mortgage monthly payments and return if the applicant
is qualified or not
def qualify(elig, diff, mortgage_monthly_payment):
qual = False
if (elig == True) and (diff > mortgage_monthly_payment):
qual = True
return qual
# the main program
# sometimes, we write a function and we want to use that in
other Python scripts as a module.
# In this example, we want to use all three functions in the
current program (script)
# the following if statement is used to tell Python that we want to
use the above-defined functions in the current Python script.
if __name__ == "__main__":
print('please enter your age:')
age = int(input())
print('Please enter the country of residence. If you are a resident
of the United States enter USA:')
country = input()
family_income = int(input('Please enter your family total monthly
income:'))
loan_payment = int(input('Please enter your family amount of
monthly loan payment:'))
edu = int(input('Please enter an estimate of your family amount of
monthly education payment:'))
groceryAndfood = int(input('Please enter your family amount of
monthly grocery and food expenses:'))
others = int(input('Please enter the amount of other expenses not
listed above:'))
requested_mortgage_amount = int(input('Please enter the amount of
the mortgage you arerequesting:'))
####### COOMPLETE ME
# we call eligible() function
# we keep the result of eligible() function in variable E and then
test E using a conditional statement to print eligible or not
eligible
E = eligible(age, country)
if E == True:
print('you are eligible')
else:
print('you are not eligible')
# calling difference_btw_incomeAndexpense() function and keeping
its outcome in Difference variable so that we can use it later on
when we call qualify() function
Difference = difference_btw_incomeAndexpense(family_income,
loan_payment, edu, groceryAndfood, others)
# calling mortgage_monthly_paymenr() function and keeping its
outcome in Mortgage_m_p variable to be used in qualify() function
later on
# fixme
# calling qualify() function using the outputs of eligible(), E,
the output of diff(), Difference, and the output of
mortgage_monthly_payment(), Mortgae_m_p
Qual = qualify(E, Difference, Mortgage_m_p)
# since Qual is either True or Fasle, we want to use it to print
a stetement to tell the user if they are qualified or not
if Qual == True:
print('you are qualified')
else:
print('you are not qualified')
I hope this works:
continued...
calling the function:
If a user is not eligible, we can end the program at that time, no need to take further inputs.
If the user is eligible, we have taken further inputs and calculated as required.
That's all.