Python Forum
Can some one help me with Compount interest program in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can some one help me with Compount interest program in python
#1
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
Reply
#2
what have you tried so far?
Reply
#3
P = int(input("Enter amount you wish to deposit: "))
right = "n"
while right == "n":
print("please enter the years")
t = int(input())
print("Are you sure enter y or n")
right = (input())
for t in range (1,11):
if t == 1:
r = ".0115"
elif t == 2:
r="0.013"
elif t == 3:
r=".015"
elif t == 4:
r=".016"
elif t == 5:
r=".0185"
elif t == 6:
r=".019"
elif t == 7:
r=".0195"
elif t == 8:
r=".02"
elif t == 9:
r=".0215"
elif t == 10:
r=".023"



payments = int(input("Enter number of times the interest is compounded per year: "))



endSum = P*(1+(r/payments))**(payments*t)
print('End sum = {0:.3f}'.format(endSum))


then I get error

35
---> 36 endSum = P*(1+(r/payments))**(payments*t)
37 print('End sum = {0:.3f}'.format(endSum))
TypeError: unsupported operand type(s) for /: 'str' and 'int'
Reply
#4
Put your code and output in proper tags.

rateList = [0.0115,0.013,0.015,0.016,0.0185,0.019,0.0195,0.02,0.0215,0.023]
def calculateCompoundInterest():
  p = float(input("Principle"))
  t = int(input("Years"))
  r=0
  sure = input("Are you sure ?").lower()
  if(sure=="y" or sure=="yes"):
    if(t>=0 and t<=10):
      r = rateList[t-1]
    else:
      return
  else:
    calculateCompoundInterest()
    
  payments = int(input("Enter number of times the interest is compounded per year: "))
  endSum = p*(1+(r/payments))**(payments*t)
  print('End sum = {0:.3f}'.format(endSum))
  
calculateCompoundInterest()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Modify an Energy Model to account for year dependent interest rate rather than only t giovanniandrean 0 425 Oct-10-2023, 07:00 AM
Last Post: giovanniandrean

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020