View Single Post
Old 03-11-2012, 10:29 PM   PM User | #2
fatecaresx13
New Coder

 
Join Date: Jan 2010
Posts: 29
Thanks: 0
Thanked 2 Times in 2 Posts
fatecaresx13 is an unknown quantity at this point
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 10:33 PM..
fatecaresx13 is offline   Reply With Quote