Exemplo n.º 1
0
 def __init__(self, poly_string=""):
     """Builds a polynomial
         If a string is given in the right format it will split it to build the polynomial"""
     self.terms = Vector()
     if poly_string != "":
         poly_pieces = Vector()
         poly_pieces.build_from_list(poly_string.split(" "))
         for i in range(0, len(poly_pieces), 2):
             coef = poly_pieces[i]
             exponent = poly_pieces[i + 1]
             self.terms.insert_rear(Term(int(coef), int(exponent)))
         #condense similar terms
         self.combine_like_terms()
         # Sort the terms
         self.sort_terms()
Exemplo n.º 2
0
 def __init__(self, poly_string=""):
     """Builds a polynomial
         If a string is given in the right format it will split it to build the polynomial"""
     self.terms = Vector()
     if poly_string != "":
         poly_pieces = Vector()
         poly_pieces.build_from_list(poly_string.split(" "))
         for i in range(0, len(poly_pieces), 2):
             coef = poly_pieces[i]
             exponent = poly_pieces[i + 1]
             self.terms.insert_rear(Term(int(coef), int(exponent)))
         #condense similar terms
         self.combine_like_terms()
         # Sort the terms
         self.sort_terms()