Created
December 10, 2023 15:33
-
-
Save gisfromscratch/9525fa83743ef822b5e9b6d2d25a7ed0 to your computer and use it in GitHub Desktop.
Solve for any one side of a triangle using the Pythagorean Theorem.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
# Function to calculate the hypotenuse | |
def calculate_hypotenuse(a, b): | |
return math.sqrt(a**2 + b**2) | |
# Function to calculate one leg (a) | |
def calculate_leg_a(c, b): | |
return math.sqrt(c**2 - b**2) | |
# Function to calculate the other leg (b) | |
def calculate_leg_b(c, a): | |
return math.sqrt(c**2 - a**2) | |
# Example values | |
a = 3 | |
b = 4 | |
c = calculate_hypotenuse(a, b) | |
# Print the results | |
print(f"The hypotenuse (c) is: {c}") | |
print(f"The length of leg a is: {calculate_leg_a(c, b)}") | |
print(f"The length of leg b is: {calculate_leg_b(c, a)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment