I am getting an error of : 'Employee' object has no attribute '_name' I have looked over my indentation and can't seem t
Posted: Fri May 20, 2022 1:41 pm
I am getting an error of : 'Employee' object has no attribute
'_name'
I have looked over my indentation and can't seem to find the
issue. Below is also the initial prompt.
Eclass Employee: def init__(self, name, id_number, salary, email): self._-_employee_name = name self.__ID_number = id_number self.__salary salary self.__email_address = email def get_name(self): return self.__employee_name def get_ID_number (self): return self.__ID_number def get_salary(self): return self.__salary def get_email_address(self): return self.__email_address Edef make_employee_dict(names_list ID_numbers_list salaries_list email_addresses_list): employee_dict = {} for vals in range(len (names_list)): emp = Employee (names_list[vals], ID_numbers_list[vals], salaries_list[vals], email_addresses_list[vals]) employee_dict(ID_numbers_list[vals]] emp return employee_dict E# emp_names = ["Jean", "Kat", "Pomona"] # emp_ids ["100", "101", "102"] # emp_sals = [30, 35, 28] # emp_emails = ["[email protected]", "[email protected]", "[email protected]"] # result = make_employee_dict(emp_names, emp_ids, emp_sals, emp_emails) # print (result["100"].get_name()).
Write a class named Employee that has private data members for an employee's name, ID_number, salary, and email_address. It should have an init method that takes four values and uses them to initialize the data members. It should have get methods named get_name, get_ID_number, get_salary, and get_email_address. Write a separate function (not part of the Employee class) named make_employee_dict that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses (which are all the same length). The function should take the first value of each list and use them to create an Employee object. It should do the same with the second value of each list, etc. to the end of the lists. As it creates these objects, it should add them to a dictionary, where the key is the ID number and the value for that key is the Employee object. The function should return the resulting dictionary. For example, it could be used like this: = emp_names ["Jean", "Kat", "Pomona"] emp_ids ["100", "101", "102"] emp_sals = [30, 35, 28] emp_emails = ["[email protected]", "[email protected]", "[email protected]"] result = make_employee_dict(emp_names, emp_ids, emp_sals, emp_emails) print(result["100"] -get_name()) = = Remember in your testing that printing an object of a user-defined class will just print out the object's type and address in memory. If you want to print the values of its data members, you need to call its get functions, as shown in the print statement above. The file must be named: make_employee_dict.py
'_name'
I have looked over my indentation and can't seem to find the
issue. Below is also the initial prompt.
Eclass Employee: def init__(self, name, id_number, salary, email): self._-_employee_name = name self.__ID_number = id_number self.__salary salary self.__email_address = email def get_name(self): return self.__employee_name def get_ID_number (self): return self.__ID_number def get_salary(self): return self.__salary def get_email_address(self): return self.__email_address Edef make_employee_dict(names_list ID_numbers_list salaries_list email_addresses_list): employee_dict = {} for vals in range(len (names_list)): emp = Employee (names_list[vals], ID_numbers_list[vals], salaries_list[vals], email_addresses_list[vals]) employee_dict(ID_numbers_list[vals]] emp return employee_dict E# emp_names = ["Jean", "Kat", "Pomona"] # emp_ids ["100", "101", "102"] # emp_sals = [30, 35, 28] # emp_emails = ["[email protected]", "[email protected]", "[email protected]"] # result = make_employee_dict(emp_names, emp_ids, emp_sals, emp_emails) # print (result["100"].get_name()).
Write a class named Employee that has private data members for an employee's name, ID_number, salary, and email_address. It should have an init method that takes four values and uses them to initialize the data members. It should have get methods named get_name, get_ID_number, get_salary, and get_email_address. Write a separate function (not part of the Employee class) named make_employee_dict that takes as parameters a list of names, a list of ID numbers, a list of salaries and a list of email addresses (which are all the same length). The function should take the first value of each list and use them to create an Employee object. It should do the same with the second value of each list, etc. to the end of the lists. As it creates these objects, it should add them to a dictionary, where the key is the ID number and the value for that key is the Employee object. The function should return the resulting dictionary. For example, it could be used like this: = emp_names ["Jean", "Kat", "Pomona"] emp_ids ["100", "101", "102"] emp_sals = [30, 35, 28] emp_emails = ["[email protected]", "[email protected]", "[email protected]"] result = make_employee_dict(emp_names, emp_ids, emp_sals, emp_emails) print(result["100"] -get_name()) = = Remember in your testing that printing an object of a user-defined class will just print out the object's type and address in memory. If you want to print the values of its data members, you need to call its get functions, as shown in the print statement above. The file must be named: make_employee_dict.py