J
joy99
Dear Group,
I was practising some early example of class if you can kindly let me
know where I was going wrong.
I am pasting directly from IDLE. There may be slight indentation
problem. I am using Python 2.6.4 on Windows XP Service Pack 3.
The Code and the output:
def _init_(self,name):
self.name=name
self.attendance=0
self.marks=[]
number_of_marks=len(self.marks)
print number_of_marks
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
b=Student("Bobby")
TypeError: this constructor takes no arguments
SyntaxError: invalid syntax def _init_(self,x,y):
self.x=x
self.y=y
description="This Shape is not been described Yet"
author="Nobody has Claimed it Yet"
def area(self):
return self*x+self*y
def perimeter(self):
return 2*self.x+2*self*y
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
rectangle=Shape(100,45)
TypeError: this constructor takes no arguments
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
print rectangle.area()
AttributeError: Shape instance has no attribute 'area'Best Regards,
Subhabrata.
I was practising some early example of class if you can kindly let me
know where I was going wrong.
I am pasting directly from IDLE. There may be slight indentation
problem. I am using Python 2.6.4 on Windows XP Service Pack 3.
The Code and the output:
def _init_(self,name):
self.name=name
self.attendance=0
self.marks=[]
number_of_marks=len(self.marks)
print number_of_marks
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
b=Student("Bobby")
TypeError: this constructor takes no arguments
SyntaxError: invalid syntax def _init_(self,x,y):
self.x=x
self.y=y
description="This Shape is not been described Yet"
author="Nobody has Claimed it Yet"
def area(self):
return self*x+self*y
def perimeter(self):
return 2*self.x+2*self*y
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
rectangle=Shape(100,45)
TypeError: this constructor takes no arguments
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
print rectangle.area()
AttributeError: Shape instance has no attribute 'area'Best Regards,
Subhabrata.