How To Get Python Compound Interest Calculator To Give The Correct Answer?
I've run into the issues of my Compound Interest Calculator giving the wrong calculation when you input the principal, compounded interest (yearly, monthly, etc..), interest rate (
Solution 1:
If you are entering interest in percentages, you should take care of that in your code.
final = P * (((1 + (r/(100.0 * n))) ** (n*t)))
Solution 2:
Based on this: Compound Interest Formula FV = P (1 + r / n)^Yn, where P is the starting principal, r is the annual interest rate, Y is the number of years invested, and n is the number of compounding periods per year. FV is the future value, meaning the amount the principal grows to after Y years.
P = int(input("Enter starting principle please. "))
n = int(input("Enter number of compounding periods per year. "))
r = float(input("Enter annual interest rate. e.g. 15 for 15% "))
y = int(input("Enter the amount of years. "))
FV = P * (((1 + ((r/100.0)/n)) ** (n*y)))
print ("The final amount after", y, "years is", FV)
Solution 3:
# name
NAME=raw_input("Enter Name= ")
# Principle amount
P =float(input("Enter Principle Amount: "))
# Rate of interest
R = float(input("Enter rate of Interest: "))
#No Of years
T = float(input("Enter No of Years= "))
#compound interest calculation
CI = P * ( 1 + R / 100)**T
print"compound interest is {:.2f}".format(CI)
Solution 4:
Please try the below Python code for Compound Interest:
p = float(input('Please enter principal amount:'))
t = float(input('Please enter number of years:'))
r = float(input('Please enter rate of interest:'))
n = float(input('Please enter number of times the interest is compounded in a year:'))
a = p*(1+(r/(100*n))**(n*t))
print('Amount compounded to: ', a)
Solution 5:
P = int(input("Enter starting principle please: "))
n = int(input("Enter number of compounding periods per year: "))
r = float(input("Enter annual interest rate: "))
y = int(input("Enter the amount of years: "))
FV = P * (((1 + ((r/100.0)/n)) ** (n*y)))
print ("The final amount after", y, "years is", FV)
Post a Comment for "How To Get Python Compound Interest Calculator To Give The Correct Answer?"