# Square Root by Newton's Method -- Recursive Version
# Functional Programming Example using Python 3.6+ Nested Functions
# H. Conrad Cunningham, Professor, Computer and Information Science
# University of Mississippi

# Developed for CSci 658, Software Language Engineering, Spring 2018

# 3456789012345678901234567890123456789012345   def sqrt_iter(guess,x):
        if good_enough(guess,x):
	        return guess
        else:
            return sqrt_iter(improve(guess,x),x)
    if x >= 0:
        return sqrt_iter(1, x)
    else:
        print(f'Cannot compute square root of negative number {x}')

if __name__ == '__main__':
    print(f'sqrt(-1) is {sqrt(-1)}')
    print(f'sqrt(0)  is {sqrt(0)}')
    print(f'sqrt(1)  is {sqrt(1)}')
    print(f'sqrt(2)  is {sqrt(2)}')
    print(f'sqrt(3)  is {sqrt(3)}')
    print(f'sqrt(4)  is {sqrt(4)}')
    print(f'sqrt(9)  is {sqrt(9)}')
    print(f'sqrt(16) is {sqrt(16)}')
