Hello. How to create a program that draws graphs of functions in MatplotLib. I have sketched something here:
# -*- coding: utf-8 -*- from numpy import * import matplotlib.pyplot as plt import math import pylab from matplotlib import mlab print("Π‘ΡΡΠΎΠΈΡΠ΅Π»Ρ Π³ΡΠ°ΡΠΈΠΊΠΎΠ²") f = input ('f(x)=') code = """ def func (x): return %s """ % f exec(code) xmin = -20.0 xmax = 20 dx = 0.01 xlist = mlab.frange (xmin, xmax, dx) ylist = [func (x) for x in xlist] plt.axis([-20, 20, -20, 20]) plt.xlabel('x') plt.ylabel('y') plt.title('ΠΡΠ°ΡΠΈΠΊ ΡΡΠ½ΠΊΡΠΈΠΈ(x)') plt.grid(True) pylab.plot (xlist, ylist) pylab.show() It's ok. But as I start to touch:
code = """ def func (x): return %s """ % f writes that there is an extra indent, but the question is: where? I want to insert here also while, so that infinitely it was possible to build graphs of functions, but I can not because of this.
Tell me how to make it so that I can infinitely build graphs of functions? :)
Who has any options?

