Compound Interest

The questions below are due on Friday June 21, 2024; 10:00:00 PM.
 
You are not logged in.

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 legend, when asked to name the greatest invention in human history, Albert Einstein simply replied: "compound interest."

As an intern at the Finance Community Company (FCC) you are assigned the task of testing the powers of compound interest. Specifically, the FCC wants you to determine how long it will take a client who makes a single deposit to a bank account to double their money with fixed interest (compounded annually.) Complete the code below according to the specifications in the comment:

Notes:

  • Use the formula for the amount after n years of annually compounded interest:
    P*(1 + i)^n
    where P is the principal and i is the interest rate.

Link to starter code file

# no imports allowed! We want you to solve this problem with loops!

def double_compound(principal, interest_rate):
    """
    Given a principal amount and a given interest rate, calculate the
    - the minimum number of years until the money has (at least) doubled
    - the account balance after that many years, rounded to 2 decimal places

    Inputs:
        principal (float) - amount initially deposited
        interest_rate (float) - number between 0 and 1 representing the
                interest rate in question, where .2 represents 20% interest.

    Returns:
        A tuple containing the account balance and number of years as described
        above. If there is no way to double the account balance, return a tuple
        containing None for both values.
    """
    pass # your code here


if __name__ == "__main__":
    # Local testing -- feel free to add your own tests as well!
    print(f"Got {double_compound(100.00, .05)=}, Expected=(207.89, 15)")

Submission

When you are ready (once you have tested on your own machine and are convinced that your program will do the right thing), upload your file below for testing:

  No file selected

Next Exercise: Polynomial Calculus

Back to exercises