Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Programming Problem 2. Polynomials Design and implement (in file p2.py) a class called Poly for representing and operating with polynomials. A polynomial in variable

Python Programming

image text in transcribedimage text in transcribed

Problem 2. Polynomials Design and implement (in file p2.py) a class called Poly for representing and operating with polynomials. A polynomial in variable x of degree n20 has this general expression: n-1 P(X) n-1 with coefficients akEIR and a, 0 Find out more about polynomials at http:llwww.mathplanet.com/education/algebra-1factoring-and-polynomialslmonomials-and polynomials or at https:LAwww.math.auckland.ac.nzlclass255408slL01s24polynomials.pdf a) The Poly class must support the following operations, illustrated with examples below: Initialization, with the constructor taking an iterable (like a list ao a a, l) that generates the coefficients, starting with ao. The coefficients are floats or ints, but the constructor must convert them to type float. The degree of the polynomial is given by the length of the sequence of the sequence. Conversion to string Str Skip terms aXK with coefficient ak 0. Use the default number of decimals for floats. Representation, for printing at the terminal Lrepr Indexing. This operation takes parameter k and returns the coefficient ak if 0K kKan or throws Value Error otherwise. If p is a Poly object plk] returns ak.Cgetitem Addition with another Poly object Ladd Multiplication with another Poly object and with a float or an int. Cmul and rmul) Testing for equality Ceq, ne Two polynomials are equal if their coefficients are respectively equal. Equal polynomials must be of the same degree. r Evaluation of the polynomial for a given value x for variable X. The method is called eval o if x is an int or float then p eval(x) returns the value of expression a, X o if x is a sequence of elements xo, xi,... (an iterable, such as a tuple or a list), then p eval(x) returns a list with the matching elements [self eval(xo), self eval(x1), 1. Use a list comprehensions for this evaluation b) Write in file p2.py a function called test poly that tests all operations and methods from part a). Use the function testif from Homework 3 or something similar. Here are examples how Poly objects could be used from the Python shell

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions