[Tutor] Student Class
dwightdhutto at gmail.com
Thu Sep 6 00:42:15 CEST 2012
On Wed, Sep 5, 2012 at 6:10 PM, Ashley Fowler
<afowler2 at broncos.uncfsu.edu>wrote:
> I need help creating a student class. I am suppose to create a student
> 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?
> for instance,
> class Student:
> def __init__(self, name, hours, gpa):
> self.name = name
> self.name is bringing a more global variable into the class, so it can
> be changed within the class, but remain the same outside of the class
> 1. four instance variables: firstName (a string), lastName (a string),
> numCredits (an integer), gpa (a float);
> Then you need the following in init:
def __init__(self, first_name,last_name, numCredits,hours, gpa):
self.first_name <http://self.name> = first_name
self.last_name = <http://self.name>last_name
self.numCredits = <http://self.name> numCredits
self.hours = <http://self.name>hours
self.gpa = <http://self.name>gpa
self.first_name = "Bob"
> 2. an accessor method for each instance variable;
> student = Student(first_name,last_name, numCredits,hours, gpa)
> 3. a mutator method for each instance variable;
> Define mutator, is that just to change?
> 4. an __init__ method that sets all the instance variables to values
> provided by the user;
> look above at the init.
> 5. a __str__ method that returns a string that contains all the data
> of the object in the order: firstName, lastName, numCredits, gpa.
> return : "%s , %s, %i, %i, i%" % (self.first_name,
> self.last_name, <http://self.name>self.numCredits, <http://self.name>
> self.hours, <http://self.name>self.gpa <http://self.name>)
or something like that.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor