Having trouble when I run this python program. I'm being told that the "Test Failed: 'Employee' object has no attribute 'get_name'" and "Test Failed: 'Employee' object has no attribute '_name'" The assignment is below, and my code is at the bottom. Please help me spot these errors and understand them. Thanks.
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
Having trouble when I run this python
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 whole 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 = ["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())
```
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.
CODE IS BELOW
class Employee:
def __init__(self, names, id_number, salary, email_address):
self.names = names
self.id_number = id_number
self.salary = salary
self.email_address = email_address
def get_names(self):
return self.names
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
def make_employee_dict(emp_names, emp_id, emp_salary, emp_email):
emp = {}
emp_len = len(emp_id)
for x in range(emp_len):
names = emp_names[z]
ID_number = emp_id[z]
salary = emp_salary[z]
email = emp_email[z]
emp[id_number] = emp(names, id_number, salary, email)
return emp
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
I am still confused about how to remedy this situation. Can you show me the section of the code that needs to be fixed? and further, explain?
I'm getting errors when I run this. Its saying "Traceback (most recent call last):
File "<string>", line 47, in <module>
File "<string>", line 30, in make_employee_dict
KeyError: ('Jean', '100', 30, 'Jean@aol.com')
> " How can this be remedied?