Reputation: 11
I am new to Python and I am currently stuck on this learning problem.
I am trying to make a program which will output the lowest common multiple of 10 required to pay off a credit card balance. Each payment is made once a month and has to be the same for each month in order to satisfy the requirements of the problem, and monthly interest must also be taken into account.
def debt(payment):
balance = 3329
annualInterestRate = 0.2
month = 1
finalbalance = balance
while month <= 12:
#Monthly interest rate
rate=(annualInterestRate / 12.0)
#Monthly unpaid balance
finalbalance = round(finalbalance - payment,2)
#Updated balance each month
finalbalance = round(finalbalance + (rate * finalbalance),2)
#Moves month forward
month = month + 1
#Shows final fingures
print('Lowest Payment: ' + str(payment))
debt(10)
The above works fine except for the fact I am lacking a mechanism to supply ever greater multiples of ten into the problem until the final balance becomes less than zero.
I posted a similar question here with different code that I deleted as I felt it could not go anywhere and I had subsequently rewrote my code anyway.
Upvotes: 1
Views: 205
Reputation: 146
If so, then you need to restructure your function. Instead of payment, use balance as the parameter. Your function should output your payment, not take it in as a parameter. Then, since you're doing this monthly, the final output (whatever it is) would be greater than balance / 12, because that would be how you pay the core debt, without interest.
So, now off we go to find the worst thing possible. The entire balance unpaid plus interests. That would be (annual rate x balance) + balance. Divide that by 12, and you get the max amount you should pay per month.
There, now that you have your min and max, you have a start and end point for a loop. Just add 1 to the payment for each loop until you get the minimum amount to pay for the included interests.
Upvotes: 1