# Arup Guha
# Second function example.
# 2/24/2020

# This is a function definition.
def main():

    # Get the user input.
    leg1 = int(input("Enter the first leg of the right triangle.\n"))
    leg2 = int(input("Enter the second leg of the right triangle.\n"))

    # Calculate the square of the hypotenuse, and then use our square root
    # function to get the hypotenuse length.
    anssqr = square(leg1) + square(leg2)
    print("The square of the hypotenuse is",anssqr)
    print("The hypotenuse is", mysqrt(anssqr))

# This function returns the square of its input value.
def square(x):
    return x*x

# Returns the square root of x.
def mysqrt(x):

    # The real square root must be in between low and high.
    low = min(1,x)
    high = max(1,x)

    # We refine our guess 100 times.
    for i in range(100):

        # Always guess halfway between our bounds.
        mid = (low+high)/2

        # This means our guess was too small, so adjust low.
        if mid*mid < x:
            low = mid

        # This means it was too big, adjust high.
        else:
            high = mid

    # This is good enough, by now low and high are very close to each other.
    return low

# Get main to run.
main()

