Question
I need help, I am getting close but I can not figure it out. :( I included MY CODE I am using to get the
I need help, I am getting close but I can not figure it out. :(
I included MY CODE I am using to get the interaction shown below in the example.
Please, use my labels (Month, Balance, Principal Interest, Payment) to get the information for the chart.
The title should be "(whatever the user input is for "what is this loan for") + Loan". Please use the numbers from the example to make the loan payment graph.
USING PYTHON, use 'import matplotlib.pyplot as plt' to create a graph for the balance remaining, as in the example below.
Make sure to use plt.yticks to assign years to the x axis and also assign $ to the y axis.
~~~~~~~MY CODE~~~~~~~~~~
# program shows the details of the loan
# will take the input values from user
loanPurpose = input("What is the loan for?")
principal = input("Please enter the principal amount for loan: ")
principal = float(principal)
remaining_principal = principal
# Declares and asks user to input interest rate. Then converts to float and input interest rate is /100/12
interest_rate = input('Please enter the yearly interest rate (as a percent) for the loan: ')
interest_rate = float(interest_rate) / 100 / 12
# Declares and asks user to input number of payments in years. Then converts to float. Years * 12 to get
# total number of months
years = input('Please enter the number of years for the loan: ')
years = float(years) * 12
# ---function for monthly loan amount calculation---
def monthly_loan(principal,interest_rate,years):
monthly_payment = (interest_rate * principal) / ( 1 - (1 + interest_rate)**(-years))
return monthly_payment
# ---funtion for remaining loan balance calculation---
def remaining_bal(remaining_principal, monthly_payment):
balance = remaining_principal - monthly_payment
return balance
# ---function for monthly interest amount calculation---
def calculate_monthly_interest(remaining_principal,interest_rate):
monthly_interest = float(interest_rate * remaining_principal)
return monthly_interest
# ---funtion for monthly principal calculation---
def monthly_principal(principal,monthly_payment, monthly_interest):
mprincipal = monthly_payment - monthly_interest
return mprincipal
print("Month ", " Balance " , "Principal", "Interest ", "Payment ")
for x in range(1, int(years+1)):
monthly_payment = monthly_loan(principal,interest_rate,years)
balance = remaining_bal(remaining_principal, monthly_payment)
monthly_interest = calculate_monthly_interest(remaining_principal,interest_rate)
mprincipal = monthly_principal(principal,monthly_payment, monthly_interest)
remaining_principal = remaining_principal - mprincipal
print(x , remaining_principal, mprincipal, monthly_interest, monthly_payment)
~~~~~~~ MY CODE ~~~~~~~~
User Interaction What is this loan for? BMW i8 Please enter the principal amount for the loan: 141695.00 Please enter the yearly interest rate (as a percent) for the loan: 4.0 Please enter the number of years for the loan: 5 Calculation Output Monthly payment: $2609.53 Total loan amount: $156571.74 Total interest paid: $14876.74 Month Balance Principal Interest Payment $141,695.00 $2,137.21$472.32$2609.5.3 $139,557.79$2,144.34 $465.19$2609.5.3 2 60 $ 2,600.80$2,600.80$ 8.67 $2609.47 0.00 $0.00 0.00 61 0.00 Loan Payment Graph BMW i8 Loan $160,000 140,000 $120,000 $100,000 $80,000 60,000 $40,000 $20,000 S0 _ Balance Remaining Principal Paid Interest Paid 4 Years User Interaction What is this loan for? BMW i8 Please enter the principal amount for the loan: 141695.00 Please enter the yearly interest rate (as a percent) for the loan: 4.0 Please enter the number of years for the loan: 5 Calculation Output Monthly payment: $2609.53 Total loan amount: $156571.74 Total interest paid: $14876.74 Month Balance Principal Interest Payment $141,695.00 $2,137.21$472.32$2609.5.3 $139,557.79$2,144.34 $465.19$2609.5.3 2 60 $ 2,600.80$2,600.80$ 8.67 $2609.47 0.00 $0.00 0.00 61 0.00 Loan Payment Graph BMW i8 Loan $160,000 140,000 $120,000 $100,000 $80,000 60,000 $40,000 $20,000 S0 _ Balance Remaining Principal Paid Interest Paid 4 Years
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started