Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help in Class declaration
#1
I am new to Python.
I have written a class for declaration of a parabola. When i am trying to access the class it is showing the error " 'int' object has no attribute 'x' ".
Please help with this code.
Thanks

class Parabola:
    def __init__(self,c0,c1,c2):
        self.c0=c0
        self.c1=c1
        self.c2=c2
        

    def __call__(self,x):
        return self.c2*x**2+self.c1.x+self.c0

    def table(self,L,R,n):
        s=''
        import numpy as np
        for x in np.linspace(L,R,n):
            y=self(x)
            s+='%12g%12g\n'%(x,y)
            return s



p=Parabola(1,-2,2)
p1=p(x=2)
print(p.table(0,2,10))
Reply
#2
Line 9 is wrong:
self.c1.x
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 716 Oct-22-2023, 10:05 PM
Last Post: deanhystad
  Variable declaration Asraful_Islam 5 2,966 Mar-25-2021, 05:31 PM
Last Post: nilamo
  makingVariable declaration mandatory rohitnirantar 5 2,968 Aug-26-2018, 08:00 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020