Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

can your write a function for the pythagorean theorem in python3?

  1. User

    can your write a function for the pythagorean theorem in python3?

  2. Assistant

    Yes, here is a function for the Pythagorean Theorem in Python3:

    def pythagorean_theorem(a, b):
        c = (a**2 + b**2) ** 0.5
        return c
    

    This function takes in the lengths of two sides of a right triangle (a and b) and calculates the length of the hypotenuse (c) using the Pythagorean Theorem.

    To use this function, simply call it and pass in the two side lengths as arguments:

    triangle_hypotenuse = pythagorean_theorem(3, 4)
    print(triangle_hypotenuse) # Output: 5.0
    

    In this example, we are calculating the hypotenuse of a right triangle with side lengths 3 and 4, which is 5 (according to the Pythagorean Theorem). The print() statement will output 5.0.