gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
can your write a function for the pythagorean theorem in python3?
- User
can your write a function for the pythagorean theorem in python3?
- 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 cThis function takes in the lengths of two sides of a right triangle (
aandb) 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.0In 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 output5.0.