In: Computer Science
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: The month number (beginning with 1) The current total balance owed The interest owed for that month
The amount of principal owed for that month The payment for that month 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.
I am using Python.
PYTHON CODE:
# getting the purchase price from the user
purchase_price=float(input('Enter the purchase price: '))
# variable for month counting
month = 1
# calculating the monthly payment
payment = purchase_price * (5/100)
# assigning the purchase price to the starting balance
starting_balance = purchase_price
# calculting the monthly interest rate
monthly_rate = (12/12) / 100
# header for tabular column
header='|{0:^7s}|{1:^17s}|{2:^16s}|{3:^17s}|{4:^9s}|{5:^16s}|'
# string for table header
m='Month'
sb='Starting Balance'
int_pay='Interest to Pay'
pri_pay='Principal to Pay'
pay='Payment'
end_bal='Ending Balance'
# printing the header
print('\n+'+'-'* 87+'+')
print(header.format(m,sb,int_pay,pri_pay,pay,end_bal))
print('+'+'-'* 87+'+')
# header for various values in the calculation
header2='|{:^7d}|{:^17.2f}|{:^16.2f}|{:^17.2f}|{:^9.2f}|{:^16.2f}|'
# looping
while starting_balance > 0:
# calculating the interest
interest = monthly_rate * starting_balance
# calculating the principal
principal = payment - interest
# temporary variable to store the starting
balance
t= starting_balance
# calculating the end balance
starting_balance -= payment
# printing the values
print(header2.format(month,t, interest,
principal,payment, starting_balance))
# incrementing the month
month+=1
print('+'+'-'* 87+'+')
SCREENSHOT FOR CODING:
SCREENSHOT FOR OUTPUT: