I am starting to learn coding and beginning with Python. In my Python course I have a problem that is the following:
Write a program to calculate the credit card balance after one year if a person only pays the minimum monthly payment required by the credit card company each month.
The following variables contain values as described below:
balance - the outstanding balance on the credit card
annualInterestRate - annual interest rate as a decimal
monthlyPaymentRate - minimum monthly payment rate as a decimal
For each month, calculate statements on the monthly payment and remaining balance, and print to screen something of the format:
Month: 1
Minimum monthly payment: 96.0
Remaining balance: 4784.0
(I've got that part alright)
Finally, print out the total amount paid that year and the remaining balance at the end of the year in the format:
Total paid: 96.0 Remaining balance: 4784.0
(It is the part of total paid that I can't resolve after many hours of trying and searching)
So here is what I need to do: add up together all the results of minimum monthly payment to get the total that was paid.
Here is my code:
def creditPayment(balance, annuelInterestRate, monthlyPaymentRate):
for month in range(1, 13):
monthlyInterestRate = annuelInterestRate/ 12.0
minimumMonthlyPayment = monthlyPaymentRate * balance
monthlyUnpaidBalance = balance - minimumMonthlyPayment
balance = monthlyUnpaidBalance + (monthlyInterestRate * monthlyUnpaidBalance)
totalPaid = sum((minimumMonthlyPayment) for _ in range(0, 13))
print 'Month: ', month
print 'Minimum monthly payment: ', round(minimumMonthlyPayment, 2)
print 'Remaining balance: ', round(balance, 2)
print ' '
print 'Total paid: ', round(totalPaid, 2)
print 'Remaining balance: ', round(balance, 2)
print creditPayment(4213, 0.2, 0.04)
Everything works fine except for the total paid that adds up 12 times only the first value of minimumMonthlyPayment. I can't make it better.