Skip to content

Instantly share code, notes, and snippets.

@briatte
Last active April 20, 2020 08:31
Show Gist options
  • Save briatte/c3319315873ff3aedb7976c83b8b5059 to your computer and use it in GitHub Desktop.
Save briatte/c3319315873ff3aedb7976c83b8b5059 to your computer and use it in GitHub Desktop.
# triangle.py
import math
def triangle_perimeter(a, b, c):
return a + b + c
def triangle_area(a, b, c):
p = triangle_perimeter(a, b, c) / 2
x = math.sqrt(p * (p - a) * (p - b) * (p - c))
return round(x, 2)
def main():
a = input("Side 1:")
a = float(a)
b = input("Side 2:")
b = float(b)
c = input("Side 3:")
c = float(c)
print("Perimeter:", triangle_perimeter(a, b, c))
print("Area:", triangle_area(a, b, c))
if __name__ == "__main__":
main()
# kthxbye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment