{}
run-icon
main.py
def f(x): y=x**3-3*x+1 return y a=float(input("Enter the 1st value of interval: ")) b=float(input("Enter the 2nd value of interval: ")) n=int(input("Enter the numbers of iterations: ")) for i in range (0,n): c=(a+b)/2 if (f(a)*f(c)<0): b=c elif (f(b)*f(c)<0): a=c print("The next interval is",(a,b)) print("The root of the given equation after all iterations is: ",((a+b)/2))
Output