Answer to Question #242605 in Python for Gopi

Question #242605
Suppose there is two different types of dictionary, one dictionary contains employee id and
name of employee and another dictionary contains employee id and salary. Take 5 employee
details. Now display the employee's designation from the following condition:
If salary between 80,000 to 90,000:designation:Project Manager
salary between 70,000 to 80,000:designation:Team Leader
salary between 60,000 to 70,000:designation:Software Developer
salary between 50,000 to 60,000:designation:Software Trainee
Display result in the form of dictionary.
1
Expert's answer
2021-09-27T01:19:16-0400
A dictionary containg the id and names for five employees
employee_id_name_dict = [
    {"id": 100, "name": "Bob"},
    {"id": 102, "name": "Kelly"},
    {"id": 105, "name": "Daniel"},
    {"id": 110, "name": "Nyamai"},
    {"id": 120, "name": "Mue"}
]
#A dictionary having the id's and salaries for the five employees
employee_id_salary_dict = [
    {"id": 100, "salary": 85000},
    {"id": 102, "salary": 74000},
    {"id": 105, "salary": 68000},
    {"id": 110, "salary": 62000},
    {"id": 120, "salary": 56000}
]

print("\tEmployees_id_designation_dictionary = ")
print("\t[")
index = 0;
while index < len(employee_id_salary_dict):
    my_id = employee_id_salary_dict[index]["id"]
    my_salary = employee_id_salary_dict[index]["salary"]
    designation = ""
    if my_salary >= 80000 and my_salary <90000:
        designation = "Project Manager"
    elif my_salary >=70000 and my_salary < 80000:
        designation = "Team Leader"
    elif my_salary >=60000 and my_salary < 70000:
        designation = "Software Developer"
    else :
        designation = "Software Trainee"
    if(index != len(employee_id_salary_dict)-1):
        print("\t\t{ 'id': "+str(my_id)+" 'designation': "+str(designation)+" },")
    else:
        print("\t\t{ 'id': " + str(my_id) + " 'designation': " + str(designation) + " }")
    index = index + 1

print("\t]")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS