Hello,
I was seeking help in why my small program/script is not performing the way I would like. Here is the question.

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.
Use raw_input() to ask for the following three floating point numbers:
1. the outstanding balance on the credit card
2. annual interest rate
3. minimum monthly payment rate
Here is my code:

balance = float(raw_input('Enter your ourstanding debt.  '))
annuainterest= float(raw_input('Enter your annual interest rate in decimal.  '))
minmonpayrate = float(raw_input('Enter your minimum monthly payment rate in decimal.  '))

for month in range(1,13):
    print 'Month: ' + str(month)
    interest = float(round(annuainterest/12*balance,2))
    minpayamount = float(round(balance*minmonpayrate,2))
    print 'Minimum monthly payment:  ' +str(minpayamount)
    principal = float(round(minpayamount-interest,2))
    print 'Principal:  ' + str(principal)
    rembalance = float(round(balance - principal,2))
    print 'Remaining Balance:  ' + str(rembalance)

The program list the months correctly but does not redue the math for each month can anyone help? Thank you!

Recommended Answers

All 3 Replies

I guess it might help to add I just began learing program yesterday so I'm pretty lost on what to do next I have been learning via the MIT open courseware website and this is one of the problems they have given after a lecture and resitation video.

None of the variables in your loop ever change, so you get the same output on each iteration of your loop. For example you set rembalance to balance - principle. Since balance and principle are never changed, balance - principle will evaluate to the same value every time, so rembalance will have the same value every time.

If you want to output different values at each iteration of the loop, at least one of the variables used in the loop needs to be changed inside the loop. Presumably that variable should be balance.

Thanks for the help, I changed rembalance to balance and it caused balance to change when it restarted the loop. This will help me in the future to remember that a variable needs to be changed for the program to redue the math the next time through. My initial thinking was that the loop would pull the initial assignment of balance evertime it ran so I thought I had to come up with some type of remainingbalance varible to redue the math. But I guess the initial balance variable does not matter after the first run though because I no longer need that number. Thanks again for your help it really caught me on to something I did not even know I was missing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.