#PLEASE LEAVE A THUMBS UP
align below program like above it works perfect a tested it
class polynomial:
"""
A class that represents a polynomial
"""
is_print_zero_terms=True
def __init__(self,*coefficients):
self.coefficients=list(coefficients)
def eval(self,x):
"""
Evaluates and return numeric value of this polynomial
"""
result = 0
for index, coeff in enumerate(self.coefficients[::-1]):
result += coeff * x** index
return result
def __str__(self):
count=len(self.coefficients) - 1
poly=''
for coeff in self.coefficients:
if coeff!=0:
if count<len(self.coefficients)-1:
if coeff<0:
poly=poly+" - "
else:
poly=poly+" + "
poly=poly+str(coeff)+".x^"+str(count)
else:
if polynomial.is_print_zero_terms==True :
poly=poly+" + "+str(coeff)+".x^"+str(count)
count-=1
return poly
pa = polynomial(1,1,1,0,1)
student_answer = pa.eval(2)
correct_answer = 29
assert student_answer == correct_answer
pe = polynomial(-1,-1,-1,0,0,-1)
student_answer = pe.eval(2)
correct_answer = -57
assert student_answer == correct_answer
polynomial.is_print_zero_terms = False
pg = polynomial(1,0,1,1,0,1)
student_answer = str(pg)
correct_answer = '1.x^5 + 1.x^3 + 1.x^2 + 1.x^0'
assert student_answer == correct_answer
Write a Python class called polynomial that represents a polynomial in the following fashion, The initializer...
Please answer this in python 3, thank you.
For this lab, you must define a class called Polynomial. This class definition must include the following methods: ._init_0- the initialiser for the class ._str_0- returns a formatted string representation of a Polynomial object add_term) - adds a new term (coefficient and exponent) to the Polynomial .addo-modifies the existing Polynomial by adding another one to it ._add_0-returns a new Polynomial object that is the sum of two polynomials scale) - scales a...
please answer this question in python 3
For this lab, you must define a class called Polynomial. This class definition must include the following methods: ._init_0- the initialiser for the class ._str_0- returns a formatted string representation of a Polynomial object add_term) - adds a new term (coefficient and exponent) to the Polynomial .addo-modifies the existing Polynomial by adding another one to it ._add_0-returns a new Polynomial object that is the sum of two polynomials scale) - scales a Polynomial...
in
C++
as Exercise P12.14. Write a class Polynomial that stores a polynomial such p(x) = 5x10 + 9x7-x-10 as a linked list of terms. A term contains the coefficient and the example, you would store p(x) as power of x. For (5,10),(9,7),(-1,1),(一10,0) Supply member functions to add, multiply, and print polynomials. Supply a com- structor that makes a polynomial from a single term. For example, the polynomia; can be constructed as Polynomial p(Term(-10, 0)); p.add (Polynomial(Term(-1, 1))); p.add (Polynomial(Term(9,...
Polynomial Using LinkedList class of Java Language Description: Implement a polynomial class using a LinkedList defined in Java (1) Define a polynomial that has the following methods for Polynomial a. public Polynomial() POSTCONDITION: Creates a polynomial represents 0 b. public Polynomial(double a0) POSTCONDITION: Creates a polynomial has a single x^0 term with coefficient a0 c. public Polynomial(Polynomial p) POSTCONDITION: Creates a polynomial is the copy of p d. public void add_to_coef(double amount, int exponent) POSTCONDITION: Adds the given amount to...
In C++: Implement a class Polynomial that uses a dynamic array of doubles to store the coefficients for a polynomial. This class does not need the method the overloaded += operator. Your class should have the following methods: Write one constructor that takes an integer n for the degree of a term and a double coefficient c for the coefficient of the term and creates the polynomial c x^n. (This constructor can be given default arguments easily to have a...
In Java. Needing help with this homework
assignment.
The following is the class I need to write up and
implement.
two maps. P15.3 Write a class Polynomial that stores a polynomial such as f(x) = 5x10 + 9x7-x-10 as a linked list of terms. A term contains the coefficient and the power of x. For example, you would store p(x) as (5,10),(9,7),(-1,1),(?10,0) Supply methods to add, multiply, and print polynomials. Supply a constructor that makes a polynomial from a single...
Which of the following versions of the polynomial class implementation provides the most space efficient representation for polynomials with a large degree and very few terms, for example: 10x+ x200. Recall that the degree of the polynomial is the largest exponent of the term with a non-zero coefficient. SELECT THE SINGLE BEST ANSWER A static array-based implementation, where only the coefficients are stored in the array, and the exponent of each term is the index of the coefficient in the...
In Java implement a class called Polynomials: This class should store the polynomial using a linked list with nodes. (do not use existing list classes in Java). This class should store only terms with non-zero coefficients. This class should store the polynomial terms in decreasing order of their powers. This class should have a constructor with no parameters that creates a polynomial with no terms, i.e. the polynomial 0. This class should have another constructor that takes a polynomial as...
You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following: Data: that hold the x-value and the y-value. They should be ints and must be private. Constructors: A default constructor that will set the values to (3, -5) A parameterized constructor that will receive 2 ints (x then y) and set the data to what is...
Description Create a polynomial class with linked lists and implement some basic functions. Specifications Polynomials are stored in a linked list of Term objects (two classes: Polynomial and Term). Term objects have two data fields: coefficient and exponent, both positive integers. Polynomial will have some methods that create linked list functionality, but not all list operations are needed; include only those used by this program. Do not use a separate linked list class. The list will be non-circular. Make a...