Advertisement
snowden_web

Untitled

Jul 25th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. class Eq:
  2.     pass
  3.  
  4. class PolEq(Eq):
  5.     def __init__(self, pol):
  6.         self.pol = pol
  7.     def __str__(self):
  8.         return str(self.pol) + " = 0"
  9.  
  10. class SqEq(PolEq):
  11.     pass    
  12.  
  13. class LineEq(PolEq):  #ax + b = 0    
  14.     def solve(self):
  15.         if self.pol[0] == self.pol[1] == 0:
  16.             return "Any number"
  17.         elif self.pol[0] == 0:
  18.             return None
  19.         else:
  20.             return -self.pol[1] / self.pol[0]
  21.  
  22. class Polynom: #a0 + a1x + a2x**2 + a3x**3 + ...
  23.     def __init__(self,a):
  24.         self.coef = a
  25.     def __str__(self):
  26.         result = str(self.coef[0])
  27.         for i in range(1, len(self.coef)):
  28.             result += " + " + str(self.coef[i]) + "x**" + str(i)        
  29.         return result
  30.    
  31.     def __getitem__(self, index):
  32.         return self.coef[index]
  33.    
  34.     def __call__(self,x):
  35.         result = self.coef[0]
  36.         for i in range(1, len(self.coef)):
  37.             result += self.coef[i] * x**i        
  38.         return result  
  39.        
  40.    
  41. p = Polynom([1,2])
  42. e = LineEq()
  43. print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement