Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- class Figura:
- def pole(self):
- pass
- def obwod(self):
- pass
- class Trojkat(Figura):
- def __init__(self,x,y,z):
- if self.x + self.y < self.z or self.x + self.z < self.y or self.y + self.z > self.x:
- raise Exception('To nie jest trojkat!')
- def pole(self):
- p = 1/2 * (self.x + self.y + self.z)
- return math.sqrt(p * (p - self.x) * (p - self.y) * (p - self.z))
- def obwod(self):
- return self.x + self.y + self.z
- class Kwadrat(Figura):
- def __init__(self,a,b,c,d):
- if self.a != self.b and self.a != c and self.a != d:
- raise Exception('To nie jest kwadrat!')
- def pole(self):
- return self.a ** 2
- def obwod(self):
- return self.a * 4
- class Prostokat(Figura):
- def __init__(self,a,b,c,d):
- self.a = a
- self.b = b
- self.c = c
- self.d = d
- if a == c and b == d:
- self.a = a
- self.b = b
- self.c = c
- self.d = d
- elif a == b and c == d:
- self.a = a
- self.b = c
- self.c = b
- self.d = d
- elif a == d and b == c:
- self.a = a
- self.b = b
- self.c = d
- self.d = c
- else:
- raise Exception('To nie jest prostokat!')
- def pole(self):
- return self.a * self.b
- def obwod(self):
- return self.a * 2 + self.b * 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement