Advertisement
1nikitas

Untitled

Mar 27th, 2022
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. class Polynomial:
  2.     def __init__(self, coefficients):
  3.         self.coefficients = coefficients
  4.  
  5.     def __call__(self, x):
  6.         return sum([self.coefficients[i] * x ** i for i in range(len(self.coefficients))])
  7.  
  8.     def __add__(self, p):
  9.         a = self.coefficients
  10.         b = p.coefficients
  11.         if len(a) < len(b):
  12.             a += [0] * (len(b) - len(a))
  13.         else:
  14.             b += [0] * (len(a) - len(b))
  15.         return Polynomial([a[i] + b[i] for i in range(len(a))])
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement