Question: Write a Python class Polynomial which captures polynomials with integer coefficients. Your class must provide at least the following features: a method to create a

Write a Python class Polynomial which captures polynomials with integer coefficients. Your class must provide at least the following features:

a method to create a polynomial by specifying a list of coefficients and a variable name as string, e.g., p=Polynomial([1,-2,3],"x") must create the polynomial 1-2x+3x2. If the coefficient list contains any value that is not an integer, a TypeError must be raised.

an implementation of the addition operator + to add polynomials that have the same variable.

conversion of a Polynomial into a string, which must return a representation of the form "1-2*x+3*x^2".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!