I am trying to create a Python script (WageEarner) that can import my PersonWorker
class. I need it to prompt for a person’s first name, last name, and phone number because it will create a PersonWorker
object using the information provided by the user. I need it to prompt the user for the hours worked for the week and the pay rate. It will print out the PersonWorker
object and weekly pay by calling the getWeeksPay
method for that object. I am new to Python so I am not familiar on how to do this.
Here is my PersonWorker
class:
class PersonWorker:
def _init_(self, firstName, lastName, phoneNo, rate=0):
self.firstName= firstName
self.lastName= lastName
self.phoneNo= phoneNo
self.rate= rate
def getFirstName(self):
return self.firstName
def getLastName(self):
return self.lastName
def getPhoneNo(self):
return self.phoneNo
def getWeeksPay(self,hours):
if rate is 0: raise Exception("Rate not set")
return hours*self.rate
def _str_(self):
stringRep = "First Name: " + self.firstName + "\n"
stringRep = "Last Name: " + self.lastName + "\n"
stringRep = "Phone Number : " + self.phoneNo + "\n"
return stringRep