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…
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) main()