Skip to content

Instantly share code, notes, and snippets.

@AndyDeNike
Last active August 30, 2019 20:36
Show Gist options
  • Save AndyDeNike/6c48265f80d89d0be518f04db9410178 to your computer and use it in GitHub Desktop.
Save AndyDeNike/6c48265f80d89d0be518f04db9410178 to your computer and use it in GitHub Desktop.

Calculate side of 90 degree triangle

Assuming we have the length of the right angled triangle's hypotenuse AND an angle of its other corners (not the 90 degree), write an equation that will give us the distance of the opposing side of the given angle.

Image of Triangle

The equation that represents this scenerio is:

side_opposite_given_angle = sin(given_angle) * hypotenuse_len

Create a function to reflect this equation and return the side_opposite_given_angle value

Note: You may need to import a certain mathematical library to access 'sin'

Note2: In python, sin() expects the value passed to it to be in radians
Could this mathematical library also have the power to convert value to radians?

Note3: Round the overall value by 2 digits!

Find the length of the side opposite to the given angle and restore peace to this triangle!

# main.py
def calculate_side(given_angle, hypotenuse_len):
pass
# tests.py
def test_varying_values1():
angle = 39
hypotenuse = 30
assert(calculate_side(angle, hypotenuse)) == 18.88
def test_varying_values2():
angle = 45
hypotenuse = 22
assert(calculate_side(angle, hypotenuse)) == 15.56
# solution.py
import math
def calculate_side(given_angle, hypotenuse_len):
return(round(math.sin(math.radians(given_angle)) * hypotenuse_len, 2))
@AndyDeNike
Copy link
Author

4 spaces is the gold standard going forward captain salute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment