'How do I plot a graph with variables using matplotlib?

coders of the internet, I am humbly trying to make a program that plots compound interest, using user input to determine the different values for it. However, when I run the program, it appears to just plot a "y=x" graph. AITA?

import numpy as np  
import matplotlib.pyplot as plt  
def graph(formula, x_range):  
    x = np.array(x_range)  
    y = eval(formula)
    plt.plot(x, y)  
    plt.show()

# Compound Interest Formula FV = P (1 + r / n)^Yn

p = int(input("Enter your starting investment amount. "))
n = int(input("Enter number of times interest applied per time period. "))
r = float(input("Enter annual interest rate. e.g. 10 for 10% "))
y = int(input("Enter the number of years you will be invested. "))


graph('x*(1+r / n)**(y*n)', range(-100, 110))


Solution 1:[1]

hey man i think your equation is linear because the var "p,n,r,y" is constants then the x*(1+r / n)**(y*n) is equal to said x*m and m=(1+r / n)**(y*n) is constant and this is a linear equation .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kareem alkoul