Original class program:
from Circle import circle
class circle:
def __init__(self,radius=1): #write def __init__(self,radius=1) to set a value
self.radius=radius
# constructer constructs the object and initializes it
def getArea(self):
return(3.142*self.radius*self.radius)
def getPerimeter(self):
return(2*3.142*self.myradius)
Using class:
def main():
c1=circle()
#If below happens
c1.radius=-1
#if above happens then negative value will be returned
c2=circle(5)
c3=circle(3)
print(c1.getArea())
print(c2.getArea())
print(c3.getArea())
main()
I was just trying to learn about classes in python. When I run the program it says that
builtins.AttributeError: 'circle' object has no attribute 'getArea'
I am not able to understand why it is happening.
getArea()method is not seen as part of thecircleclass. Also, why are you importingCircle.circlethen overriding it with a new class?from Circle import circleis useless if you then immediately redefinecircle. This cannot be how you were taught to do things.