w3resource

Python: Compute the future value of a specified principal amount, rate of interest, and a number of years

Python Basic: Exercise-39 with Solution

Write a Python program to compute the future value of a specified principal amount, rate of interest, and a number of years.

The formula for future value with compound interest is FV = P(1 + r/n)^nt.
FV = the future value;
P = the principal;
r = the annual interest rate expressed as a decimal;
n = the number of times interest is paid each year;
t = time in years.

Test Data : amt = 10000, int = 3.5, years = 7
Expected Output : 12722.79

Sample Solution:

Python Code:

amt = 10000
int = 3.5
years = 7
future_value = amt*((1+(0.01*int)) ** years)
print(round(future_value,2))

Sample Output:

12722.79
chart: Compute the future value of a specified principal amount, rate of interest, and a number of years.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:


Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to solve (x + y) * (x + y).
Next: Write a Python program to compute the distance between the points (x1, y1) and (x2, y2).

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Unpack variables from iterable:

# One can unpack all iterables (tuples, list etc)
>>> a, b, c = 1, 2, 3
>>> a, b, c
(1, 2, 3)

>>> a, b, c = [1, 2, 3]
>>> a, b, c
(1, 2, 3)