so far i have: class Student: 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 getFirstname(self): return self.first_name def getLastname(self): return self.last_name def getNumCredits(self): return self.numCredits def getGpa(self): return self.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 def __str__(self): return (self.first_name, self.last_name, self.numCredits, self.gpa) ________________________________________ From: Tutor [tutor-bounces+afowler2=broncos.uncfsu....@python.org] on behalf of Alan Gauld [alan.ga...@btinternet.com] Sent: Wednesday, September 05, 2012 11:39 PM To: tutor@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 better. > 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 __init__() method. > 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. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor