I am trying to run the following code:
#!/usr/local/bin/python3
class Worker:
def __init__(self, name, pay):
self.name = name
self.pay = pay
def lastName(self):
return self.name.split()[-1]
def giveRaise(self, percent):
self.pay *= (1.0 + percent)
bob = Worker('Bob Smith', 50000)
sue = Worker('Sue Jones', 60000)
bob.lastName()
sue.lastName()
sue.giveRaise(.10)
sue.pay
It is throwing the following error:
AttributeError: ‘Worker’ object has no attribute ‘lastName’
I went through to make sure my indentation was correct and it seems to be fine. I put it through an online syntax checker and it didn’t catch anything.
I tried adding parentheses after Worker but that didn’t change the behavior at all.
I’m sure this is something simple I’m overlooking. I’ve looked at other answers related to this error and nothing has been the right fit.
Adrienne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.