import numpy as np def f(x): return x**3 - 6*x**2 + 4*x + 12 n = 10000 # number of x-values x = np.linspace(-2, 5, n) x_sol = -np.inf for i in range(0, n-1): if f(x[i])*f(x[i+1]) <= 0: x_sol = (x[i] + x[i+1])/2 print(f'Losning: {x_sol:.2e}')