Compound Interest
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Description
According to the story, when asked to name the greatest invention in human history, Albert Einstein simply replied: "compound interest."
Imagine putting your money in a bank account with a fixed interest rate (compounded annually) and letting it sit, without adding any more money yourself. How long will you have to wait until your money has doubled? In this question, we'll write a program to find out!
The first line in your program should define a variable called interest_rate
:
interest_rate = .05
interest_rate
will be a floating point number between 0 and 1 representing the
interest rate in question. When run, it should print a single integer
representing the minimum number of years you'll have to wait until your money
has (at least) doubled.
You can use the formula for the amount after n years of annually compounded interest:
For example, say you had a principal of 100
and an interest rate of .05
. The code should print 15
since 100*1.05**15
is 207
while 100*1.05**14
is only 198
.
If the provided interest rate is 0, your code should print NEVER
.
Notes
- Our Python checker is particular about variable names, and so it is important that you call the variable mentioned above
interest_rate
, rather than giving it a different name. Variables other than that one can be called whetever you like.
Testing
Make sure to write and test your code by hand before using Python. Draw environment diagrams for a few different test cases. Then, only once you're convinced it will work, run your code with Python on your own machine as a test.
Submission
When you are ready (once you have simulated by hand and tested on your own machine and are convinced that your program will do the right thing), upload your file below for testing: