Skip to content

Instantly share code, notes, and snippets.

@briatte

briatte/triangle.py

Last active Apr 20, 2020
Embed
What would you like to do?
# 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