Python Forum
Can some one help me with Compount interest program in python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Can some one help me with Compount interest program in python (/thread-5158.html)



Can some one help me with Compount interest program in python - soumya123 - Sep-20-2017

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


RE: Can some one help me with Compount interest program in python - Larz60+ - Sep-20-2017

what have you tried so far?


RE: Can some one help me with Compount interest program in python - soumya123 - Sep-21-2017

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'


RE: Can some one help me with Compount interest program in python - Sagar - Sep-21-2017

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()