Editorial for Triangle
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
from math import sqrt # you may use this function to calculate the area
class Triangle:
# accepts the three sides of triangle
def __init__(self, s0, s1, s2):
self.side = [s0, s1, s2]
# return the perimeter of this triangle.
@property
def perimeter(self):
return sum(self.side)
# return the area of this triangle.
@property
def area(self):
a = self.side[0]
b = self.side[1]
c = self.side[2]
s = (a+b+c)/2
return sqrt(s*(s-a)*(s-b)*(s-c))
Comments