Skip to content
TheChatArchiveThe Chat Archive
Human-written demonstration (No Robots annotators)· unknownHugging Face No Robots — Human-Written Demonstrations

Could you make me a Pythagorean theorem program with Python that will print the…

  1. User

    Could you make me a Pythagorean theorem program with Python that will print the hypotenuse length?

  2. Assistant

    Sure, I've written this program to return the hypotenuse of a right triangle using the Pythagorean theorem:

    Import the math module

    import math

    Get the lengths of the sides

    a = int(input("Side a: ")) b = int(input("Side b: "))

    Take the square root of the added squares

    c = math.sqrt(a2 + b2) print(c)

    Importing the math module allows use of the .sqrt() function. The program requests input for the opposite and adjacent sides of the right triangle as a and b, squares them with the ** operator, and takes the square root of the sum of the squares for c.