Advertisement
Guest User

Untitled

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