Question

In: Computer Science

Please fix this python code for me DOWN_PAYMENT_RATE = 0.10 ANNUAL_INTEREST_RATE = 0.12 MONTHLY_PAYMENTS_RATE = 0.05...

Please fix this python code for me

DOWN_PAYMENT_RATE = 0.10
ANNUAL_INTEREST_RATE = 0.12
MONTHLY_PAYMENTS_RATE = 0.05
purchasePrice = float(input("Enter the purchase price: "))
month = 1
payment = purchasePrice * MONTHLY_PAYMENTS_RATE
startingBalance = purchasePrice
print("\n%s%19s%18s%19s%10s%17s" % ("Month", "Starting Balance", "Interest to Pay", "Principal to Pay", "Payment", "Ending Balance"))
while startingBalance > 0:
    interestToPay = startingBalance * ANNUAL_INTEREST_RATE / 12
    principalToPay = payment - interestToPay
    endingBalance = startingBalance - payment
    print("%2d%16.2f%16.2f%18.2f%18.2f%15.2f" % (month, startingBalance, interestToPay, principalToPay, payment, endingBalance))
    startingBalance = endingBalance
    month = month + 1


#############################################################################################################

It's only going to 18 months and needs to hit 23 months

Enter the puchase price: 200

Month  Starting Balance  Interest to Pay  Principal to Pay  Payment  Ending Balance
 1         180.00           1.80             7.20             9.00           172.80
 2         172.80           1.73             7.27             9.00           165.53
 3         165.53           1.66             7.34             9.00           158.18
 4         158.18           1.58             7.42             9.00           150.77
 5         150.77           1.51             7.49             9.00           143.27
 6         143.27           1.43             7.57             9.00           135.71
 7         135.71           1.36             7.64             9.00           128.06
 8         128.06           1.28             7.72             9.00           120.34
 9         120.34           1.20             7.80             9.00           112.55
10         112.55           1.13             7.87             9.00           104.67
11         104.67           1.05             7.95             9.00            96.72
12          96.72           0.97             8.03             9.00            88.69
13          88.69           0.89             8.11             9.00            80.57
14          80.57           0.81             8.19             9.00            72.38
15          72.38           0.72             8.28             9.00            64.10
16          64.10           0.64             8.36             9.00            55.74
17          55.74           0.56             8.44             9.00            47.30
18          47.30           0.47             8.53             9.00            38.77
19          38.77           0.39             8.61             9.00            30.16
20          30.16           0.30             8.70             9.00            21.46
21          21.46           0.21             8.79             9.00            12.68
22          12.68           0.13             8.87             9.00             3.80
23           3.80           0.00             3.80             3.80             0.00

##############################################################################################################

"

The credit plan at TidBit Computer Store specifies a 10% down payment and an annual interest rate of 12%. Monthly payments are 5% of the listed purchase price, minus the down payment.

Write a program that takes the purchase price as input. The program should display a table, with appropriate headers, of a payment schedule for the lifetime of the loan. Each row of the table should contain the following items:

  1. The month number (beginning with 1)
  2. The current total balance owed
  3. The interest owed for that month
  4. The amount of principal owed for that month
  5. The payment for that month
  6. The balance remaining after payment

The amount of interest for a month is equal to balance × rate / 12.

The amount of principal for a month is equal to the monthly payment minus the interest owed.

An example of the program input and output is shown below:

"

Solutions

Expert Solution

'''

Python version : 3.6

Python program to display a table, with appropriate headers, of a payment schedule for the lifetime of the loan

'''

DOWN_PAYMENT_RATE = 0.10

ANNUAL_INTEREST_RATE = 0.12

MONTHLY_PAYMENTS_RATE = 0.05

purchasePrice = float(input("Enter the purchase price: "))

month = 1

startingBalance = purchasePrice - (purchasePrice*DOWN_PAYMENT_RATE) # subtract down payment from list price

payment = startingBalance * MONTHLY_PAYMENTS_RATE # calculate the monthly payment from the startingBalance

monthly_interest_rate = ANNUAL_INTEREST_RATE/12 # calculate the monthly interest

print("\n%s%19s%18s%19s%10s%17s" % ("Month", "Starting Balance", "Interest to Pay", "Principal to Pay", "Payment", "Ending Balance"))

while startingBalance > 0:

               # if startingBalance < monthly payment

               if startingBalance < payment:

                              principalToPay = startingBalance # principal = remaining balance

                              payment = startingBalance # payment = remaining balance

                              interestToPay = 0 # interest = 0

               else:

                              interestToPay = startingBalance * monthly_interest_rate # calculate the interest for the month

                              principalToPay = payment - interestToPay # calculate the principal for the month by subtracting the interest owed for the month

                             

               endingBalance = startingBalance - principalToPay # get the ending balance by accounting the interest

              

               print("%2d%16.2f%16.2f%18.2f%18.2f%15.2f" % (month, startingBalance, interestToPay, principalToPay, payment, endingBalance))

               startingBalance = endingBalance

               month = month + 1

#end of program

Code Screenshot:

Output:


Related Solutions

fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
Please fix all of the errors in this Python Code. import math """ A collection of...
Please fix all of the errors in this Python Code. import math """ A collection of methods for dealing with triangles specified by the length of three sides (a, b, c) If the sides cannot form a triangle,then return None for the value """ ## @TODO - add the errlog method and use wolf fencing to identify the errors in this code def validate_triangle(sides): """ This method should return True if and only if the sides form a valid triangle...
I need to fix this code, and could you please tell me what was the problem...
I need to fix this code, and could you please tell me what was the problem options 1 and 9 don't work #include <stdio.h> #include <time.h> #include <stdlib.h> // generate a random integer between lower and upper values int GenerateRandomInt(int lower, int upper){     int num =(rand()% (upper - lower+1))+lower;     return num; } // use random numbers to set the values of the matrix void InitializeMatrix(int row, int column, int dimension, int mat[][dimension]){     for(int i =0; i<row; i++){...
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
Python 3 Fix the code so if the user does not select a value in the...
Python 3 Fix the code so if the user does not select a value in the sold by field, it shows a warning message indicating "Choose one value" import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) #...
Python 3 Fix the code and rovide the correct indentation Code: import tkinter as tk from...
Python 3 Fix the code and rovide the correct indentation Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window) product = tk.Entry(window) money =...
Python 3 Fix the code so if the user enter the same bar code more than...
Python 3 Fix the code so if the user enter the same bar code more than three times, it shows a warning message indicating that the product was already tested 3 times and it reached the limits Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1, weight=1) window.grid_rowconfigure(1, weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20,...
Can someone please explain to me why "return 1" in this Python code returns the factorial...
Can someone please explain to me why "return 1" in this Python code returns the factorial of a given number? I understand recursion, but I do not understand why factorial(5) returns 120 when it clearly says to return 1. def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
Python 3 Fix the code so i can make the window larger or smaller and the...
Python 3 Fix the code so i can make the window larger or smaller and the fields adjusts everytime according to the window size import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook window = tk.Tk() window.title("daily logs") # window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT