public
anonymous / gist:6116132
Created

Fully revised.

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
outbal= float(raw_input('enter the outstanding balance on your credit card:'))
annualrate= float(round(raw_input('Enter the annual credit card interest rate as a decimal:')), 2)
monthlyrate= round(annualrate/year, 2)
month=1
x = 1
while (remainder > 0):
while (month <= 12):
initialmonthlyballance = round(float(((annualrate /12)*outbal)+outbal, 2)
remainder = round(float(initialmonthlyballance - x10))
print "Outbal minus payment equals:" remainder
if (y >= 0):
month = month + 1
outbal = remainder
if (remainder > 0):
x = x + 1
Else:
if (remainder <= 0):
print 'Monthly payment to pay off debt in 1 year:', x10
print 'number of months needed:', month
print 'Balance:' remainder

Before going farther and look at the way to deal with loops, you should fix issues regarding your variables.

  • Keep variable name short : for example, "initialmonthlyballance" is too long, and it is prone to typo error (see the way you wrote "ballance")

  • Keep the same name. There is a variable called "y" coming from nowhere at line 11. Same remark apply for a variable "x10" at line 9 and 18. You probably renamed these variables somewhere, but forgot these places.

  • Use existing variable. At line 3 you create "monthlyrate" but still, you recalculate the monthly rate at line 8. Why not using existing "monthlyrate" ?

  • Generally, if you want to manipulate a variable, this variable must exist. Here, at line 6, you create a loop based on the value of a variable called "remainder", but such variable does not exist... How can Python check its value if its not stated elsewhere before ?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.