[Tutor] Student Class

eryksun eryksun at gmail.com
Thu Sep 6 08:05:34 CEST 2012

On Wed, Sep 5, 2012 at 7:43 PM, Ashley Fowler
<afowler2 at broncos.uncfsu.edu> wrote:
> class Student:

Are you using Python 3? If not, Student should explicitly inherit from object.

>     def __init__(self, first_name, last_name, numCredits, gpa):
>         self.first_name = first_name
>         self.last_name = last_name
>         self.numCredits = numCredits
>         self.gpa = gpa

Your requirements specify firstName and lastName, not first_name and last_name.

>         def getFirstname(self):
>             return self.first_name

All of the function definitions below __init__ need to be dedented one
level. You have them defined in __init__.

>         def setFirstname(self, first_name):
>             self.first_name = first

'first' isn't defined. You named the parameter "first_name".

>         def setLastname(self, last_name):
>             self.last_name = last

Neither is 'last' defined.

>         def setNumcredits(self, numCredits):
>             self.NumCredits = credit

Neither is 'credit' defined. Plus this method creates a new attribute
named NumCredits. The name in __init__ is numCredits.

>         def __str__(self):
>             return (self.first_name, self.last_name, self.numCredits, self.gpa)

The __str__ method absolutely needs to return a string. Use string
formatting via 'format' or the old modulo formatting.


More information about the Tutor mailing list