Few early questions on Class

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top