Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Eq:
- pass
- class PolEq(Eq):
- def __init__(self, pol):
- self.pol = pol
- def __str__(self):
- return str(self.pol) + " = 0"
- class SqEq(PolEq):
- pass
- class LineEq(PolEq): #ax + b = 0
- def solve(self):
- if self.pol[0] == self.pol[1] == 0:
- return "Any number"
- elif self.pol[0] == 0:
- return None
- else:
- return -self.pol[1] / self.pol[0]
- class Polynom: #a0 + a1x + a2x**2 + a3x**3 + ...
- def __init__(self,a):
- self.coef = a
- def __str__(self):
- result = str(self.coef[0])
- for i in range(1, len(self.coef)):
- result += " + " + str(self.coef[i]) + "x**" + str(i)
- return result
- def __getitem__(self, index):
- return self.coef[index]
- def __call__(self,x):
- result = self.coef[0]
- for i in range(1, len(self.coef)):
- result += self.coef[i] * x**i
- return result
- p = Polynom([1,2])
- e = LineEq()
- print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement