Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com APR Interest Calculator help

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 02-06-2012, 04:11 AM PM User | #1 mikefallen New to the CF scene   Join Date: Feb 2012 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts APR Interest Calculator help I'm taking an introductory course to python and I'm having really frustrating time as this is very simple and i have done programming much more complex and just getting really frustrated on being hung up on this. So my assignment is to create a calculator that does APR interest using the formula Where A is the monthly payment, P is the total amount borrowed (the principal), n is the number of months for repayment and i is the monthly interest rate. You can calculate the monthly interest rate by dividing the annual interest rate ("APR") by 12. For example, to borrow \$30,000 (P) for a 10 year term (n = 120) with an APR interest rate of 6% (i = 0.06 / 12 = 0.005), A calculates to be \$333.06 - the monthly payment. The total interest paid over 10 years (always depressing!) = 120 * \$333.06 - \$30,000 = \$9,967.38. Code: ```def main(): print("****************************************") print("Mortgage Calculator v1.0") print("****************************************") print("") principal = float(input("Principal Amount ")) years = int(input("Input number of years ")) interest = float(input("Input interest percentage ")) interest = (interest/100)/12 months = years*12 monthly_payments = principal*interest/1-(1+interest)**-months print(apr) print("After", Years, "years at", format(interest, '.0%'), " interest ", "total is", format(Total, '.2f')) print("Monthly payments will be", monthly_payments) print("Total interest will amount to", format(total_interest, '.2f')) main()```
 03-11-2012, 11:29 PM PM User | #2 fatecaresx13 New Coder   Join Date: Jan 2010 Posts: 29 Thanks: 0 Thanked 2 Times in 2 Posts So just as a starting point it may be helpful to have another function to handle calculations and a function to handle input and call the calculating function. Not sure which variables you'd want to have but here: Code: ```def apr(principal, years, interest): top = principal*interest; bottom = 1 - (1+interest)**(-1*years); return round(top/bottom, 2); def main(): print apr(1000, 1, 0.06); print apr(1000, 2, 0.06); print apr(1000, 3, 0.06); main();``` This probably is incorrect, but it's helpful to show you a cleaner way to format your code to find issues much faster. And you can unit test easier. If you want to test you can type 'python' import your code (if the filename is 'apr' then 'import apr' and test like so 'apr.apr(principal, years, interest)'; That should help you test faster. Now you handle the input. Make sure you convert to int() or float() where appropriate. __________________ Nerd Stuff (code, rrdtool, monitoring, etc): blog.anthonyhurst.com Last edited by fatecaresx13; 03-11-2012 at 11:33 PM..

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 07:19 PM.