I am trying to create a python class based on this class. I am trying to have it return the person’s wages for the week (including time and a half for any overtime. I need to place this method following the def getPhoneNo(self): method and before the def __str__(self):
method because I am trying to use this method in another program. I f anyone can help out.
class PersonWorker: def _init_(self, firstName, lastName, phoneNo): self.firstName= firstName self.lastName= lastName self.phoneNo= phoneNo def getFirstName(self): return self.firstName def getLastName(self): return self.lastName def getPhoneNo(self): return self.phoneNo def _str_(self): stringRep = "First Name: " + self.firstName + "\n" stringRep = "Last Name: " + self.lastName + "\n" stringRep = "Phone Number : " + self.phoneNo + "\n" return stringRep`: def getWeeksPay(self, hours, rate)
I see two issues in the example you posted:
I updated your code snippet with an example of what I think you are trying to accomplish.
Is the
__str__
function looking alright? I mean stringRep is changed several times and the last version is returned.I think the body of the function should look like this: