denis.spir at free.fr
Fri Dec 11 15:59:01 CET 2009
"Roshan S" <roshan.s at live.com> dixit:
> class Student:
> print"We have a new student "
> def __init__(self,name='',credit=0,grade=0,quality=0):
> def inputstudent(self):
> self.name=raw_input("Enter student Name ")
> self.credit=input("What da credit hours ")
> self.grade=input("What da grade ")
> def quality(self):
> print"Quality Points: ",self.quality
> def average(self):
> print"Grade point average: "+self.grade
> if gpa == 4: print "Grade: A"
> elif gpa == 3: print "Grade: B"
> elif gpa == 2: print "Grade: C"
> elif gpa == 1: print "Grade: D"
> def outputstudent(self):
> "Name: "+self.name
> #create new student
> #run teh method
> We have a new student
> Enter student Name r
> What da credit hours 3
> What da grade 5
> Traceback (most recent call last):
> File "C:\Users\Roshan\Desktop\no3.py", line 38, in <module>
> TypeError: 'int' object is not callable
> PYTHON version 2.6.3, windows 7
You've got 2 attributes called 'quality'. One is a method that is defined on the class, the other a piece of data later defined on the student object itself at init time. The second one will override the method, hiding it. Python does not make a difference between behaviour attributes (methods) and state ones (data), so you cannot have a method called like a piece of data.
Anyway, in your case the method is an *action* that sets and prints out an attribute, so its name should reflect this fact.
la vita e estrany
More information about the Tutor