Below is code I wrote for calculating credit card interest, balances, etc. How do I correct my code to properly format for $ signs with 2 decimal points? Right now, my code is just printing numbers without the $ sign and more than two decimal points? Also, how do I correct my code so that the RESULT and Total Amount Paid and Remaining Balance print only once at the end of the run? Finally, the += and -=... is that just shorthand for adding and subtracting whatever is on the right side of that equation? balance = float(input('Enter the outstanding balance on your credit card: ')) ann_In
ballance = 143.287592 print "$" + str(round(ballance,2))
Just as an example, I set the ballance to something that would round.
you can use string formatting: http://dpaste.com/1315730/ http://docs.python.org/2.7/library/stdtypes.html#str.format http://docs.python.org/2.7/library/string.html#string-formatting or the locale module - http://dpaste.com/1315739/ http://docs.python.org/2.7/library/locale.html
Join our real-time social learning platform and learn together with your friends!