Python Forum
Investment calculator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Investment calculator
#1
Hello

Anyway, my assignment question is to create a program that acts as an investment calculator using the following formula:

S = P(1+j/n)^nt

Answer needs to in float

def invest_calc(P,j,t):
    n = 12
    S = P(1+j/n)**n*t
    return invest_calc(P,j,t)

P=float(input("Enter initial value: "))
j=float(input("Enter the annual interest rate: "))
t = float(input("Enter the time: "))

print(invest_calc(P,j,t))
I get the following error

TypeError: 'float' object is not callable for Var S. I have tried adding brackets, removing brackets, adding a multiplication for n and t. But no luck. Can anyone assist?

Thanks in advance
Reply
#2
Ok, so I realized why.. I was writing the formula as you do in Maths, so Python did not recognize. I have called the function and seem to get the same answer as the example on my assignment sheet. BUT I get a weird statement after.

New code:
def invest_calc(P,j,t):
    n = 12
    S=P*(1+j/n)**(n*t)
    return S

P=float(input("Enter initial value: "))
j=float(input("Enter the annual interest rate: "))
t = float(input("Enter the time: "))
S = invest_calc

print(invest_calc(P,j,t), S)
Enter initial value: 5000

Enter the annual interest rate: .05

Enter the time: 10

8235.0474884514 <function invest_calc at 0x7fb57a95c9d8>

Any suggestions?
Reply
#3
You have already called function, S = invest_calc do not call only show memory location.
def invest_calc(P,j,t):
    n = 12
    S = P * (1+j/n) ** (n*t)
    return S

P = float(input("Enter initial value: "))
j = float(input("Enter the annual interest rate: "))
t = float(input("Enter the time: "))
result = invest_calc(P,j,t)
print(result)
Single variable name is not making any code readable.
def invest_calc(value, rate, time):
    n = 12
    result = value * (1+rate/n) ** (n*time)
    return result

value = float(input("Enter initial value: "))
rate = float(input("Enter the annual interest rate: "))
time = float(input("Enter the time: "))
result = invest_calc(value, rate, time)
print(result)
Reply


Forum Jump:

User Panel Messages

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