Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7815227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:27:34+00:00 2026-06-02T05:27:34+00:00

Im doing a class for polynomial and i have a problem with a copy

  • 0

Im doing a class for polynomial and i have a problem with a copy function. It suppose to create a copy of the Poly object and return a reference to the new Poly object. Im really stuck on this copy idea. Thanks for any help

class Poly:

    def __init__ (self, p):
        self.a = p
        self.deg= len(p) -1
        if len(p) == 1 and p[0] == 0:
            self.deg = -1

    def evalPoly(self,x0):
        ''' evaluates the polynomial at value x'''
        b=0
        for coefficients in reversed(self.a):
            b=b*x0+int(coefficients)
        return b

    def polyPrime(self):
        '''replaces the coeffiecients of self with the coefficients           
        of the derivative polynomial '''
        if self.deg == 0:
            return np.zeroes(1,float), 0
        else:
            newdeg=self.deg-1
            p=[i*self.a[i] for i in range(1,self.deg+1)]
            p=str(p)[1: -1]
            p=eval(p)
        return p

    def copy(self):
        return Poly(self.a)

I’m stuck on how to create a copy of the Poly object and return a reference to the new Poly object

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:27:36+00:00Added an answer on June 2, 2026 at 5:27 am

    I think the problem you are having is that as self.a is a list then you are passing a reference to that list in the instantiation of the new Poly object.

    You should copy the list and give that copy to instantiate the object:

    import copy
    
    class Poly:
        ...
        def copy(self):
            return Poly(copy.copy(self.a))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i hope you can help me with my problem: I have a Class doing
I have code that looks like this: public class Polynomial { List<Term> term =
Is there a good library (preferably gem) for doing class checking of an object?
When doing this : class MyClass { public $myAttr; } $c = new MyClass();
let's say if you have class doing something on some other thread. And has
I have a class in which I create the database. I want to do
I have the following code in a project I am doing for class. I
In ActionScript 3, when I create a class I generally extend Object : public
I'm playing around with scala (scala 2.8). Suppose I have a class with a
What principles do you generally follow when doing class design?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.