# Interest.py (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-04-18 File created. # 2022-12-16 Converted to Python 3. # The initialized table below is a tuple. A tuple in Python is # an initialized sequence of data that is immutable, i.e., # you cannot add new items to a tuple or replace items in a # tuple once the tuple is created. compound_interest_table = \ ( ( 5.00, 10.25, 15.76, 21.55, 27.63, 34.01, 40.71, 47.75 ), ( 6.00, 12.36, 19.10, 26.25, 33.82, 41.85, 50.36, 59.38 ), ( 7.00, 14.49, 22.50, 31.08, 40.26, 50.07, 60.58, 71.82 ) ) print( "\n This program calculates the compound interest" \ "\n for a given sum of money (principal). \n" \ "\n Give the loan amount: ", end="" ) given_sum_of_money = float( input() ) print( "\n Give the interest percentage ( 5, 6, or 7): ", end="" ) interest_percentage = int( input() ) print( "\n Give the loan period in years ( max. 8 ): ", end="" ) loan_period_in_years = int( input() ) print( "\n For a loan of %.2f you must pay " \ "\n %.2f as compound interest after %d years." % \ ( given_sum_of_money, ( given_sum_of_money / 100.0 ) * compound_interest_table[ interest_percentage - 5 ] [ loan_period_in_years - 1 ], loan_period_in_years ) ) # The table above could be defined as a list and the program # would operate in the same way as it operates now. The table # could be defined as a list by using brackets instead of # parentheses in the following way: #compound_interest_table = \ # [ # [ 5.00, 10.25, 15.76, 21.55, 27.63, 34.01, 40.71, 47.75 ], # [ 6.00, 12.36, 19.10, 26.25, 33.82, 41.85, 50.36, 59.38 ], # [ 7.00, 14.49, 22.50, 31.08, 40.26, 50.07, 60.58, 71.82 ] # ]