Last active
November 6, 2015 18:08
-
-
Save apalii/ecc7576f22274fa8308d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class TriangleError(Exception): | |
"""docstring for TriangleError | |
error.args - single element tuple which conteins the msg passed to | |
the constructor""" | |
def __init__(self, text, sides): | |
super().__init__(text) | |
self.sides = tuple(sides) | |
@property | |
def sides(self): | |
return self._sides | |
def __str__(): | |
return "'{}' for sides {}".format(self.args[0], self._sides) | |
def __repr__(): | |
"TriangleError({!r}, {!r}".format(self.args[0], self._sides) | |
def triagle_areas(a, b, c): | |
sides = sorted((a, b, c)) | |
if sides [2] > sides[0] + sides[1]: | |
raise TriangleError("Illegal troangle", sides) | |
p = (a + b + c) / 2 | |
return math.sqrt(p * (p - a) * (p - b) * (p - c)) |
Author
apalii
commented
Nov 6, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment