[Tutor] Student Class
afowler2 at broncos.uncfsu.edu
Thu Sep 6 01:43:11 CEST 2012
so far i have:
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
def setFirstname(self, first_name):
self.first_name = first
def setLastname(self, last_name):
self.last_name = last
def setNumcredits(self, numCredits):
self.NumCredits = credit
def setGpa(self, gpa):
self.gpa = gpa
return (self.first_name, self.last_name, self.numCredits, self.gpa)
From: Tutor [tutor-bounces+afowler2=broncos.uncfsu.edu at python.org] on behalf of Alan Gauld [alan.gauld at btinternet.com]
Sent: Wednesday, September 05, 2012 11:39 PM
To: tutor at python.org
Subject: Re: [Tutor] Student Class
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
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
More information about the Tutor