#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2017
    Posts
    1
    Rep Power
    0

    Calculate Compount Interest in Python


    Can some one help me with Compount interest program in python ?

    Here are my specs:

    User will input amount of initial deposit.
    They will also enter the number of years they want the CD for.
    The program will then ask the user if they are sure on the length of time chosen before continuing on.
    The application will print out each year’s interest accrued and have a running total of amount in the CD.
    The interest for this program will be compounded only once a year.
    Depending on the length of their deposit, they will have a different interest rate.
    The interest rates are below

    CD Rates

    1 year 1.15%
    2 year 1.3%
    3 year 1.5%
    4 year 1.6%
    5 year 1.85%
    6 year 1.9%
    7 year 1.95%
    8 year 2.00%
    9 year 2.15%
    10 year 2.3 %

    At the end of the CD’s term, it will display a sum of all interest accrued and total amount that is in the CD account.

    any help is highly appreciated
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,896
    Rep Power
    509
    You could use
    Code:
    # dictionary of interest rate accessed by year.
    rate = {
        1:  1.15,
        2:  1.3,
        3:  1.5,
        4:  1.6,
        5:  1.85,
        6:  1.9,
        7:  1.95,
        8:  2.00,
        9:  2.15,
        10: 2.3,
    }
    And you might use a loop to compute compound interest over the years.
    Perhaps you'd store the original investment, then you could subtract to find the amount of accumulated interest.
    You might need to convert string to float or int.
    Code:
    $ python3
    Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
    [GCC 6.3.0 20170118] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> int('4')
    4
    >>> float('124.23')
    124.23
    >>>
    balance = original_balance
    for year in years: balance *= interest_rate
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,896
    Rep Power
    509
    You could use
    Code:
    # dictionary of interest rate accessed by year.
    rate = {
        1:  1.15,
        2:  1.3,
        3:  1.5,
        4:  1.6,
        5:  1.85,
        6:  1.9,
        7:  1.95,
        8:  2.00,
        9:  2.15,
        10: 2.3,
    }
    And you might use a loop to compute compound interest over the years.
    Perhaps you'd store the original investment, then you could subtract to find the amount of accumulated interest.
    You might need to convert string to float or int.
    Code:
    $ python3
    Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
    [GCC 6.3.0 20170118] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> int('4')
    4
    >>> float('124.23')
    124.23
    >>>
    balance = original_balance
    for year in years: balance *= 1 + interest_rate
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo