import matplotlib.pyplot as plt import numpy as np x0 = 100 # initial amount p = 5 # interest rate N = 4 # number of years index_set = range(N+1) x = np.zeros(len(index_set)) # Compute solution x[0] = x0 for n in index_set[1:]: x[n] = x[n-1] + (p/100.0)*x[n-1] print(x) plt.plot(index_set, x, 'ro') plt.xlabel('years') plt.ylabel('amount') plt.show()