# -*- coding: utf-8 -*-
import sys #This module provides access to some variables used or maintained
import math
import numpy as np
from colorama import Fore,Back #used to color the print

def f(c): return  ((9.8*68.1)/c)*(1-(math.exp(-10*c/68.1)))-40
     

eps = 1e-2
print(eps)
a, b = 12., 16.

fa = f(a)
if fa*f(b) > 0: #If the times fa and fb are greater than 0, terminate the process. (There is no root in this range.)
    print ('f(x) does not change sign in [%g,%g].' % (a, b))
    sys.exit(1)
"""
exit(0) means a clean exit without any errors / problems.A zero error code means a successful exit.

exit(1) means there was some issue / error / problem and that is why the program is exiting.
the error code indicates what the problem was.
""" 
i = 0 # There is no root in this range.Iteration ends at 0.
while b-a > eps: #Continue the process as long as it fulfills the condition.
    i += 1
    m = (a + b)/2.0
    fm = f(m)
    if fa*fm <= 0:
        b = m  
    else:
        a = m  
        fa = fm
    
    Ea=np.fabs((b-a)/b)*100
    print (Fore.LIGHTBLACK_EX+Back.WHITE,'Iteration %d: interval=[%g, %g]' % (i, a, b))
    print(Fore.LIGHTBLACK_EX+Back.YELLOW,'Ea(%)=',Ea) 
    x = m         
    print (Fore.LIGHTBLACK_EX+Back.YELLOW,'f(%g)=%g' % (x, f(x)))
    print(Fore.LIGHTRED_EX+Back.YELLOW,'fa*fm=',fa*fm)
    

    

  

