[Tutor] Student Class
alan.gauld at btinternet.com
Thu Sep 6 01:39:25 CEST 2012
On 05/09/12 23:10, Ashley Fowler wrote:
> I need help creating a student class.
We don't do your homework for you we will only offer hints. So you need
to show us what you are trying and we will try to steer you to something
> class with there first name, last name, credits
> and gpa. Can anybody help me get started? Below is what needs to be
> included. For number one, is the variables
> suppose to be parameters?
Normally yes, you'd make those variables the input parameters to the
> 1. four instance variables: firstName (a string), lastName (a string),
> numCredits (an integer), gpa (a float);
These would normally be defined inside __init__()
> 2. an accessor method for each instance variable;
> 3. a mutator method for each instance variable;
This is not good Python practice. It smells like Java...
In python it's customary to access attributes directly.
If you really want to use access methods then you
should create a 'property'
> 4. an __init__ method that sets all the instance variables to values
> provided by the user;
> 5. a __str__ method that returns a string that contains all the data
> of the object in the order: firstName, lastName, numCredits, gpa.
These are fairly standard.
Author of the Learn to Program web site
More information about the Tutor