Https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-classes/lessons/data-types/exercises/methods-with-arguments

link to exercise: https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-classes/lessons/data-types/exercises/methods-with-arguments

Hi everyone,
If I define a class variable, I would’ve expected any methods I create to be able to reference it. However, it doesn’t look to be the case. For example I defined class variable pi = 3.14, and then create a method that calculates the area, which is based on pi. I have to define it again in the method to avoid a typeError. Is this how it is, or did I miss something?

class Circle:
  pi = 3.14
  def area(self, radius):
    pi = 3.14
    area = pi * radius ** 2
    return area

Your code looks a bit stange normally you first had to intialize all variable in a method and then build a function to calculate the value. Here a example how it normaly looks

Blockquote
class Point3D(object):
def init(self,x,y,z):
self.x=x
self.y=y
self.z=z
def repr(self):
return “(%d, %d, %d)”%(self.x,self.y,self.z)