Geeking out big time

I did it again today

I went to school 6 hours early so I could just do a bunch of programming. Im working on Python right now, I actually finished all of my homework so I am just playing around. What just I did is so cool; there was a program we had to write to calculate the interest an account accumulates over time. The challenge given to us was simple, to make the user to be able to input not only the principal and interest rate, but also how many years they want to calculate for. Simple.

I thought something was missing…

Wouldn’t it be nice if you could see the value of each year up to your final calculated year? Well I already had the years stored in a variable… so I slapped a print statement in the for loop I used to make the calculation.

It was so cool!

I first ran the module for a ten year calculation, I was so excited! I looked really nice. So nice that I wanted to see a thousand year investment…

This slideshow requires JavaScript.

My source code:

def main():
    print("This program calculates an investments value over time")
    principal = eval(input("Enter the initial principal:"))
    apr = eval(input("Enter the annual interest rate:"))
    years = eval(input("Enter how many years ahead you would like to calculate:"))

    for i in range (years):
        principal = principal * (1+apr)
        print("year" ,i+1 ,principal)

    print("The value in year",years, "will be", principal)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s