In the cell below, write a class to represent an employee as per following specifications:
Class name: Employee
Instance attributes: as defined by the items in object employee_51 i.e. employee_id, firstname, etc.
_init_() method: should initialise instance attributes to the value of the parameters passed to the method
set_firstname() method: to set the firstname in the instance variable to the value of the parameter passed
get_name() method: to get the full name formatted as lastname, firstname
After having defined the class, you need to test the class and its methods to show that it works. You can do this as follows:
Instantiate an object of the class and pass employee_51 to the initialiser
Set the firstname to something different by calling set_firstname() and passing it the appropriate parameter
employee_51 = {
"email": "paul4823.rogers@gmail.com",
"employee_id": 51,
"firstname": "Paul",
"lastname": "Rogers",
"title": "Mr",
"work_phone": "(02) 5829 2608"
}
# Write your code here
# Define the class here
# Instantiate the class and call its methods here
employee_51 = {
"email": "paul4823.rogers@gmail.com",
"employee_id": 51,
"firstname": "Paul",
"lastname": "Rogers",
"title": "Mr",
"work_phone": "(02) 5829 2608"
}
# Write your code here
# Define the class here
class Employee:
def __init__(self, emp):
self.email = emp["email"]
self.employee_id = emp["employee_id"]
self.firstname = emp["firstname"]
self.lastname = emp["lastname"]
self.title = emp["title"]
self.work_phone = emp["work_phone"]
def set_firstname(self, fn):
self.firstname = fn
def get_name(self):
return "{},{}".format(self.lastname,self.firstname)
# Instantiate the class and call its methods here
p = Employee(employee_51)
print("email:",p.email)
print("firstname:",p.firstname)
p.set_firstname("asdf")
print("firstname:",p.firstname)
print(p.get_name())
您好,我是问答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632