Could you tell me how to fix the error in testing the following code: class Employee: """ The employee class has a constructor and getter methods. The constructor has input arguments""" # Assigns values for id, name, salary, and email from input arguments def __init__(self, i, n, s, e): self.id = i self.name = n self.sal = s self.email = e # getter function for name def get_name(self): return self.name # getter function for ID def get_id(self): return self.id # getter function for salary def get_sal(self): return self.sal # getter function for email def get_email(self): return self.email def make_employee_dict(ids, names, sal, emails): """Function to create employee object and the dictionary using those objects""" # k is the length of all the lists k = len(ids) emp_dict = dict() # Making employee object and adding to dictionary for i in range(k): e = Employee(ids[i], names[i], sal[i], emails[i]) emp_dict[ids[i]] = e # return the dictionary return emp_dict # Testing emp_names = ["Jean", "Kat", "Pomona"] emp_ids = ["100", "101", "102"] emp_sals = [30, 35, 28] emp_emails = ["Jean@aol.com", "Kat@aol.com", "Pomona@aol.com"] result = make_employee_dict(emp_names, emp_ids, emp_sals, emp_emails) print(result["100"].get_name())
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Could you tell me how to fix the error in testing the following code:
class Employee:
""" The employee class has a constructor and getter methods.
The constructor has input arguments"""
# Assigns values for id, name, salary, and email from input arguments
def __init__(self, i, n, s, e):
self.id = i
self.name = n
self.sal = s
self.email = e
# getter function for name
def get_name(self):
return self.name
# getter function for ID
def get_id(self):
return self.id
# getter function for salary
def get_sal(self):
return self.sal
# getter function for email
def get_email(self):
return self.email
def make_employee_dict(ids, names, sal, emails):
"""Function to create employee object and the dictionary
using those objects"""
# k is the length of all the lists
k = len(ids)
emp_dict = dict()
# Making employee object and adding to dictionary
for i in range(k):
e = Employee(ids[i], names[i], sal[i], emails[i])
emp_dict[ids[i]] = e
# return the dictionary
return emp_dict
# Testing
emp_names = ["Jean", "Kat", "Pomona"]
emp_ids = ["100", "101", "102"]
emp_sals = [30, 35, 28]
emp_emails = ["Jean@aol.com", "Kat@aol.com", "Pomona@aol.com"]
result = make_employee_dict(emp_names, emp_ids, emp_sals, emp_emails)
print(result["100"].get_name())
Trending now
This is a popular solution!
Step by step
Solved in 2 steps