Monomi con Python
Sto scrivendo una classe per gestire i monomi con Python. Questo รจ il costruttore:
class Monomial:
"""A class which provides some methods to manage monomials"""
def __init__(self, coefficient, *args, **kwargs):
"""Build a list which has for first element the
coefficient of the monomial and for second a dictionary
that has for keys the unknown quantities and for values
the grade of the unknown quantities.
Example:
>>> myMonomial = Monomial(3, x=1, y=3)
>>> print myMonomial.structure()
[3, {'x': 1, 'y': 2}]
>>> print myMonomial
3xy^2
"""
self.letteralPart = {}
self.coefficient = Rational(coefficient)
self.monomial = [self.coefficient, self.letteralPart]
for unknown in kwargs.items():
## unknown[0] -> letter of the unknown quantity
## unknown[1] -> grade of the unknown quantity
self.letteralPart[unknown[0]] = unknown[1]