# -*- coding: utf-8 -*- def bisection(a,b): fa=f(a) fb=f(b) if fa*fb>0: print('f(a) and f(b) must have different sign') return None #If there is no root, terminate the process if it does not fulfil the condition. for i in range(50): c=(a+b)/2 fc=f(c) if fc== 0: break if fa*fc>0: a, fa =c,fc if fb*fc>0: b, fb =c,fc return c def f(x): return x**3-10*x**2+5 a=0 b=1 x=bisection(a,b) print(x)