from math import * def f(x): return sin(x)-0.2 def solve(f,a,b,epsilon): if f(a)*f(b)>0: return print("no zero found; refine bounds") else: while (b-a)>=epsilon: c=(a+b)/2 if f(b)*f(c)<=0: a=c else: b=c return c
Create, edit, and import your Python scripts
from math import * def f(x): return sin(x)-0.2 def solve(f,a,b,epsilon): if f(a)*f(b)>0: return print("no zero found; refine bounds") else: while (b-a)>=epsilon: c=(a+b)/2 if f(b)*f(c)<=0: a=c else: b=c return c