Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import math
  2.  
  3. class Figura:
  4.     def pole(self):
  5.         pass
  6.  
  7.     def obwod(self):
  8.         pass
  9.  
  10.  
  11. class Trojkat(Figura):
  12.     def __init__(self,x,y,z):
  13.         if self.x + self.y < self.z or self.x + self.z < self.y or self.y + self.z > self.x:
  14.             raise Exception('To nie jest trojkat!')
  15.  
  16.     def pole(self):
  17.         p = 1/2 * (self.x + self.y + self.z)
  18.         return math.sqrt(p * (p - self.x) * (p - self.y) * (p - self.z))
  19.  
  20.     def obwod(self):
  21.         return self.x + self.y + self.z
  22.  
  23.  
  24. class Kwadrat(Figura):
  25.     def __init__(self,a,b,c,d):
  26.         if self.a != self.b and self.a != c and self.a != d:
  27.             raise Exception('To nie jest kwadrat!')
  28.  
  29.     def pole(self):
  30.         return self.a ** 2
  31.  
  32.     def obwod(self):
  33.         return self.a * 4
  34.  
  35.  
  36. class Prostokat(Figura):
  37.     def __init__(self,a,b,c,d):
  38.         self.a = a
  39.         self.b = b
  40.         self.c = c
  41.         self.d = d
  42.         if a == c and b == d:
  43.             self.a = a
  44.             self.b = b
  45.             self.c = c
  46.             self.d = d
  47.         elif a == b and c == d:
  48.             self.a = a
  49.             self.b = c
  50.             self.c = b
  51.             self.d = d
  52.         elif a == d and b == c:
  53.             self.a = a
  54.             self.b = b
  55.             self.c = d
  56.             self.d = c
  57.         else:
  58.             raise Exception('To nie jest prostokat!')
  59.  
  60.     def pole(self):
  61.         return self.a * self.b
  62.  
  63.     def obwod(self):
  64.         return self.a * 2 + self.b * 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement