Interest Calculator In Python
<p><strong>Interest Calculator</strong> Let the user calculate the amount of money they will have in the bank after their interest has compounded for a certain number of years. </p>

<p>Note: A = P(1+r)^t where A = total amount, P = principal, r = rate, and t = time.</p>

<p>This is what I tried: </p>

<pre><code>principal = input("How much money do you currently have in the bank?")
rate = input("What is your interest rate?")
time = input("Over how many years is the interest compounded?")
actual_principal = float(principal)
actual_rate = float(rate)
actual_time = int(time)

#TODO: Calculate the total amount and print the result
A = (actual_principal(1 + actual_rate) ^ actual_time) 
print(A)
</code></pre>

<p>I used actual_principal, actual_rate, and actual_time to convert the strings into (exact) integers...I used float instead of int because float will maintain an input with decimals, right?</p>

<p>But I got an error message on line 9</p>

<pre><code>TypeError: 'float' object is not callable on line 9
</code></pre>

<p>I'm assuming that the 'float' object refers to either actual_principal or actual_rate, or both, since those are the two values that I converted. Why, then, aren't they callable? How can I fix this program to calculate interest correctly? Thank you!  </p>

<p><strong>EDIT</strong> </p>

<p>Learning that the power function in python is ** and that implied multiplication operators don't exist in python syntax, I reworked my equation to look like this: </p>

<pre><code>final_actual_rate = actual_rate + 1
B = actual_principal * final_actual_rate
A = B ** actual_time
print(A)
</code></pre>

<p>When entering 13.58 for "How much money do you currently have in the bank?", 0.3 for "What is your interest rate?", and 5 for "Over how many years is the interest compounded?", I got the answer 1714808.43561 - so the calculator works! </p>

<p><strong>EDIT 2</strong></p>

<p>Replacing my way with this equation is the better / cleaner way to create the interest calculator - both will get you the same result: </p>

<pre><code>A = math.pow(actual_principal*(1 + actual_rate) , actual_time) 
print(A)
</code></pre>

<pre><code>import math
principal = input("How much money do you currently have in the bank?")
rate = input("What is your interest rate?")
time = input("Over how many years is the interest compounded?")
actual_principal = float(principal)
actual_rate = float(rate)
actual_time = int(time)

#TODO: Calculate the total amount and print the result
A = math.pow(actual_principal*(1 + actual_rate) , actual_time) 
print(A)
</code></pre>

<p>A few things wrong with what you have. <code>^</code> is not what you think it is in Python. <code>^</code> is an XOR binary operator not power. If you want power you use <a href="https://docs.python.org/3/library/math.html#math.pow" rel="nofollow">math.pow() module.</a></p>

<p>Also using <code>action_principal(1 + actual_rate)</code> is wrong. You are trying to call the function <code>action_principal</code> with the argument <code>1 + actual_rate</code> instead of multiplying it. Try <code>*</code> instead. </p>

python integer calculator