Investment calculator - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Investment calculator (/thread-9549.html) |
Investment calculator - beardedkiwi - Apr-16-2018 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 RE: Investment calculator - beardedkiwi - Apr-16-2018 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? RE: Investment calculator - snippsat - Apr-16-2018 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) |