Please answer this in python 3, thank you.
Please find the code below:::
class Polynomial:
def __init__(self):
self.p1 = 0
def __str__(self):
if self.p1==0:
return "0"
returnMe = ""
first = True
for key in sorted(self.p1,reverse=True):
power = key
printMe = self.p1[key]
if(printMe==0):
continue
elif printMe==1:
if not first:
returnMe +=" + "
elif printMe<0:
returnMe +=" - "
returnMe +=str(-1*printMe)
else:
if not first:
returnMe +=" + "
returnMe +=str(1*printMe)
if power==1:
returnMe+="X"
elif power==0:
returnMe+=""
else:
returnMe+="X^"+str(power)
first = False
return returnMe
def add_term(self,a,b):
if self.p1 ==0:
self.p1 = {}
self.p1[b] = a
def evaluate(self,i):
result = 0
for key in (self.p1):
result += self.p1[key]*pow(i,key)
return result
def scale(self,i):
for key in (self.p1):
self.p1[key] = self.p1[key]*i
def __add__(self,p):
copyP = Polynomial()
for key in (self.p1):
copyP.add_term(self.p1[key],key)
for key in (p.p1):
if key in copyP.p1:
copyP.p1[key] = copyP.p1[key] + p.p1[key]
else:
copyP.p1[key] = p.p1[key]
return copyP
def main():
p1 = Polynomial()
p1.add_term(10,2)
p1.add_term(-5,0)
p2 = Polynomial()
p2.add_term(5,-1)
p2.add_term(-10,2)
p3 = p1+p2
print("p1 = ",p1)
print("p2 = ",p2)
print("p3 = ",p3)
main()
For this lab, you must define a class called Polynomial. This class definition must include the f...
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...
A polynomial p(x) is an expression in variable x which is in the form axn + bxn-1 + …. + jx + k, where a, b, …, j, k are real numbers, and n is a non-negative integer. n is called the degree of polynomial. Every term in a polynomial consists of a coefficient and an exponent. For example, for the first term axn, a is the coefficient and n is the exponent. This assignment is about representing and computing...
Create a class to represent a term in an algebraic expression. As defined here, a term consists of an integer coefficient and a nonnegative integer exponent. E.g. in the term 4x2, the coefficient is 4 and the exponent 2 in -6x8, the coefficient is -6 and the exponent 8 Your class will have a constructor that creates a Term object with a coefficient and exponent passed as parameters, and accessor methods that return the coefficient and the exponent. Your class...
The second lab continues with the Polynomial class from the first lab by adding new methods for polynomial arithmetic to its source code. (There is no inheritance or polymorphism taking place yet in this lab.) Since the class Polynomial is designed to be immutable, none of the following methods should modify the objects this or other in any way, but return the result of that arithmetic operation as a brand new Polynomial object created inside that method. public Polynomial add(Polynomial...
the language is java if you coukd shiwnstep by step on how to get each section ebapps/blackboard/execute/content/file?cmd-view&content jid _975287 1&course id:_693311 Lab 3 Directions (linked lists) Program #1 1. Show PolynomialADT interface 2. Create the PolyNodeClass with the following methods: default constructor, . overloaded constructor, copy constructor, setCoefficient, setExponent, setNext, getCoefficient, getExponent, getNext 3. Create the PolynomialDataStrucClass with the following methods: defaut constructor, overloaded constructor, copy constructor, isEmpty. setFirstNode. getfirstNode,addPolyNodeFirst (PolyNode is created and set to the end of polynomial),...
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...
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...
Write a Python class called polynomial that represents a polynomial in the following fashion, The initializer of your polynomial class will be designed to take any number of numeric coefficients, The coefficient with the highest power will be the first coefficient. The last coefficient will be the constant value, that is, the value that is associated with . power 0. • Therefore, the number of the coefficients specified will directly indicate the highest power of the polynomial to be represented....
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,...
Its a report . Implement and test a preliminary version of the polynomial class, using a small array to store the coefficients of the polynomial in order of increasing exponents, following the design pattern of object-oriented approach. Suppose the range of the exponents is in [0, 30). • Use an array as a private member variable. • insert(), adding a new term on specific exponent. • remove(), deleting a term. • Have a add() method, deciding the parameters and the...