In the round function, what means the number 2 as the second argument?
##This is a program that calcs your credit card, and compounds down the total
a=float(raw_input("Enter the outstanding balance on your credit card:"))
b=float(raw_input("Enter the annual crdit card interest rate as a deicimal:"))
c=float(raw_input("Enter the minimum monthly payment as a decimal:"))
for month in range(1, 13):
print "Month: ", str(month)
MMP = round((c * a),2) ##the 2 here and below, what does it do?
print "Minimum monthly payment: ", MMP
IP = round((b/12 * a),2)
print "Interest payed: ", IP
PP = round(((c*a) - ((b/12)*a)),2)
print "principal payed: ", PP
a = round((a - PP),2)
print "Remaining balance", a
The 2 is passed as the second argument to round, giving the number of decimal places to round to. This will round it to the nearest float representing the number rounded to two decimal places. Note that this is a very bad idea and a common source of bugs. Use a fractions.Fraction or decimal.Decimal instead.
Floats should never be used for money, especially when you’re rounding them like this.