Human-written demonstration (No Robots annotators)· unknown
No Robots — Human-Written Demonstrations
Could you make me a Pythagorean theorem program with Python that will print the…
- User
Could you make me a Pythagorean theorem program with Python that will print the hypotenuse length?
- 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
mathmodule allows use of the.sqrt()function. The program requests input for the opposite and adjacent sides of the right triangle asaandb, squares them with the**operator, and takes the square root of the sum of the squares forc.