Code for calculating the minimum monthly repayment of a credit card per year

Please, I'm trying to find out what is wrong with my reasoning, and therefore my results. I am studying an online course where I have to calculate the minimum indicator needed to eliminate credit card debt within 12 months. I am given an annual interest rate, the cost of debt (balance) and the cost by which monthly payments should increase (total 10). For my reasons, my code is generated to iterate over the months, but if the balance value is not zero, it should increase the monthly payments and recount. My values ​​(I think) are a little from the expected results. My code is as follows:

annualInterestRate = 0.2
monthlyInterestRate = annualInterestRate / 12.0
monthlyPayment = 10

while (balance > 0):

    for each in range(0, 12):
        balance = balance - monthlyPayment
        balance = balance + (monthlyInterestRate * balance)
        if (balance > 0):
            monthlyPayment += 10
        else:
            break

print monthlyPayment

For balance = 3329, annual interest rate of 0.2, My result: 310 (correct)

= 4773, 0,2, : 380 (, 440)

= 3926 0,2, : 340 (, 360).

, - , ?

!

+4
4

. .

-, reset , .

-, , , . 10 , , , , . , , 10 12 .

, else: break , while, .

startBalance = int(input("what the stating balance? "))
balance = startBalance
numMonths = 12

annualInterestRate = 0.2
monthlyInterestRate = annualInterestRate / 12.0
monthlyPayment = 10

while (balance > 0):
    balance = startBalance # reset the balance each iteration

    print('checking monthly payment of',monthlyPayment)
    for each in range(0, numMonths):
        balance = balance - monthlyPayment
        balance = balance + (monthlyInterestRate * balance)
        # print('at month',each,'the balance is',balance)

    # changed the indentation below
    if (balance > 0):
        monthlyPayment += 10

print('you should pay',monthlyPayment,'per month')
+2
  • , if for each . if .

  • reset .

, .

+1

:

annualInterestRate = 0.2
monthlyInterestRate = annualInterestRate / 12.0
monthlyPayment = 10
running = true;

while (running):

    currentBalance = balance

    for each in range(0, 12):
        currentBalance = currentBalance - monthlyPayment
        currentBalance = currentBalance + (monthlyInterestRate * currentBalance)
    if (currentBalance > 0):
        monthlyPayment += 10
    else:
        running = false

print monthlyPayment

, if-condition for-each, . while (running) .

( while (currentBalance > 0), currentBalance , (), do-until-loop)

+1
Outstanding = 59400 # Total Outstanding Amount
interestrate = 4.2  # Interest Rate per month+ GST

#print("Month", "\t", "Interest+GST", "\t\t", "MinAmtDue", "\t\t\t", "Balance")
#print("-----", "\t\t", "-------", "\t\t", "--------", "\t\t\t", "-------")

month = 0
totpmt = 0
interest_GST = 0
minamtdue = 0
outstandingamt1 = Outstanding
while (outstandingamt1 + interest_GST - minamtdue) > 0 :
    month += 1
    interest_GST = outstandingamt1*4.2/100
    minamtdue = outstandingamt1 * 5/100
    #minamtdue = 12000
    outstandingamt1 = outstandingamt1 + interest_GST - minamtdue
    #print(month, "\t\t\t", round(interest_GST,2), "\t\t", round(minamtdue,2), "\t\t\t", round(outstandingamt1,2))
    totpmt = totpmt + minamtdue
#print(month+1, "\t\t\t", 0, "\t\t", round(outstandingamt1,2), "\t\t\t", 0)
print("Total Amount to be paid in ", month+1, "months= ", round(totpmt+outstandingamt1 , 2))
0

Source: https://habr.com/ru/post/1626392/


All Articles