''' mbinary ######################################################################### # File : polynomial.py # Author: mbinary # Mail: zhuheqin1@gmail.com # Blog: https://mbinary.xyz # Github: https://github.com/mbinary # Created Time: 2018-05-19 23:07 # Description: ######################################################################### ''' #!/bin/python3 # notice that creating a class's initialization won't conflict with __call__ method # because the former call class ,and the latter call instance # to be implemented class polynomial: pls= [] n = 0 def dictize(pl): if isinstance(pl,int) or isinstance(pl,float): pl = {0:pl} if isinstance(pl,polynomial): pl = pl.polynomial.copy() return pl def isZero(n): return abs(n)<0.000001 def __init__(self,s='0 0'): polynomial.pls.append(self) polynomial.n +=1 if isinstance(s,polynomial): self.polynomial=s.polynomial.copy() # don't write like this .**self.polynomial = s.polynomial**,it's ref return elif isinstance(s,dict): self.polynomial = s.copy() return s= s.replace(',',' ') s= s.replace('x',' ') s= s.replace('x^',' ') s = s.replace(':',' ') s = s.replace('\n',' ') s = s.split(' ') num = len(s) i = 0 print(s) self.polynomial = dict() li = [float(i) for i in s] while i