Search code examples
pythonpython-3.7

why doesn't it shows no result,but shows no error


I have written a code to get a root of a function.But it doesn't show any result.neither does it shows any error:

import math
from math import e
#finding root of f(x)=(e**-x)-x:
#f'(x)=(-e**-x)-1
#y=x-(f(x)/f'(x))
def f(x):
    x=0
    y=x-(((e**-x)-x)/((-e**-x)-1))
    z=((y-x)/y)*100
    while z<(10**-8):
        print(f"The root is {y}")
        x=y
    

Solution

  • from math import e
    
    
    def f():
        x = 0
        y = x-(((e**-x)-x)/((-e**-x)-1))
        z = ((y-x)/y)*100
        print(z)
        while z < (10**-8):
            print("The root is {}".format(y))
            x = y
    
    f()
    

    The Output for Z is 100

    Which Greater Than (10**-8) so while loop never works