[Tutor] Student Class

Dwight Hutto 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
> called.
> 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
    def whatever(self.first_name):
        self.first_name = "Bob"
        return self.first_name

> 2. an accessor method for each instance variable;
> student = Student(first_name,last_name, numCredits,hours, gpa)

> student.whatever():

> 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.
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120905/f1a6b9c1/attachment-0001.html>

More information about the Tutor mailing list