Ekvationslösning med intervallhalveringsmetoden

def fcn(x: float):
    px = x ** 5 - 3 * x ** 4 - 4 * x ** 3 + 12 * x ** 2 - 2
    return px

def halvering(a, b):
    while b - a > 0.001:
        m = (a + b) / 2
        if fcn(a) * fcn(m) < 0:
            b = m
        else:
            a = m
    return a


gradtal = 5
interval = [-50, 50]
tolerans = 0.1
max_ = interval[1]
k_ = interval[0]
for i in range(gradtal):
    while True:
        if abs(fcn(k_)) < tolerans:
            rot = halvering(k_ - 0.1, k_ + 0.1)
            print(round(rot, 3), end=' ')
            k_ = k_ + 0.2
            break
        k_ = k_ + 0.001