Skip to content

Instantly share code, notes, and snippets.

@kthy
Last active July 15, 2021 09:41
Show Gist options
  • Save kthy/f71476e9d970cb1239c59e0aaff585f3 to your computer and use it in GitHub Desktop.
Save kthy/f71476e9d970cb1239c59e0aaff585f3 to your computer and use it in GitHub Desktop.
TKT-DAP p01e20_usemodule
"""Triangle geometry functions."""
from math import sqrt
__version__ = '1.0.0'
__author__ = 'Kristian Thy <k@pyxy.dk>'
def hypothenuse(a: float, b: float) -> float:
"""Return the length of the hypothenuse when given the lengths of
two other sides of a right-angled triangle.
"""
return sqrt(a**2 + b**2)
def area(a: float, b: float) -> float:
"""Return the area of the right-angled triangle when two sides,
perpendicular to each other, are given as parameters.
"""
return a * b / 2
#!/usr/bin/env python3
try:
from src import triangle
except ModuleNotFoundError:
import triangle
from math import sqrt
def main():
actual = triangle.hypothenuse(1, 1)
expected = sqrt(2)
# assert actual == expected
actual = triangle.hypothenuse(3, 4)
expected = 5
# assert actual == expected
actual = triangle.area(2, 3)
expected = 3
# assert actual == expected
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment