Challenge: Generate Employee Report
As you move further into reporting and insights in HR, it is crucial to be comfortable iterating through lists of dictionaries and performing calculations based on their contents. In previous chapters, you have already worked with employee data structured as dictionaries, each containing fields such as name, department, and tenure. These skills allow you to efficiently count, summarize, and analyze HR information for reporting purposes.
When you need to generate an employee report, you often start by traversing the employee list. For each employee, you extract the department and tenure, and then use this information to compute totals, averages, and groupings. This process not only helps in summarizing the workforce but also in identifying trends and making data-driven decisions.
123456789101112131415161718192021222324252627employees = [ {"name": "Alice", "department": "HR", "tenure": 3}, {"name": "Bob", "department": "Finance", "tenure": 5}, {"name": "Charlie", "department": "HR", "tenure": 2}, {"name": "Diana", "department": "IT", "tenure": 4}, {"name": "Eve", "department": "Finance", "tenure": 1} ] # Count employees per department dept_counts = {} for emp in employees: dept = emp["department"] if dept not in dept_counts: dept_counts[dept] = 0 dept_counts[dept] += 1 print("Employee count per department:") for dept, count in dept_counts.items(): print(f"{dept}: {count}") # Calculate average tenure total_tenure = 0 for emp in employees: total_tenure += emp["tenure"] average_tenure = total_tenure / len(employees) print(f"Average tenure: {average_tenure:.2f} years")
When formatting a report for HR, clarity and organization are key. Use clear headings such as Employee Report or Departments to divide sections. Align numbers for readability and use consistent spacing. Consider breaking the report into logical parts: a title, a summary of total employees, a section listing departments with their respective employee counts, and a final section showing the average tenure. This structure ensures that your report is both informative and easy to read, making it valuable for stakeholders who rely on these insights for decision-making.
Swipe to start coding
Write a function that prints a formatted employee report using the provided list of employee dictionaries. The report must include the following sections:
- A title at the top of the report.
- The total number of employees.
- A list of departments with the count of employees in each.
- The average tenure of all employees, rounded to two decimal places.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Großartig!
Completion Rate verbessert auf 4.76
Challenge: Generate Employee Report
Swipe um das Menü anzuzeigen
As you move further into reporting and insights in HR, it is crucial to be comfortable iterating through lists of dictionaries and performing calculations based on their contents. In previous chapters, you have already worked with employee data structured as dictionaries, each containing fields such as name, department, and tenure. These skills allow you to efficiently count, summarize, and analyze HR information for reporting purposes.
When you need to generate an employee report, you often start by traversing the employee list. For each employee, you extract the department and tenure, and then use this information to compute totals, averages, and groupings. This process not only helps in summarizing the workforce but also in identifying trends and making data-driven decisions.
123456789101112131415161718192021222324252627employees = [ {"name": "Alice", "department": "HR", "tenure": 3}, {"name": "Bob", "department": "Finance", "tenure": 5}, {"name": "Charlie", "department": "HR", "tenure": 2}, {"name": "Diana", "department": "IT", "tenure": 4}, {"name": "Eve", "department": "Finance", "tenure": 1} ] # Count employees per department dept_counts = {} for emp in employees: dept = emp["department"] if dept not in dept_counts: dept_counts[dept] = 0 dept_counts[dept] += 1 print("Employee count per department:") for dept, count in dept_counts.items(): print(f"{dept}: {count}") # Calculate average tenure total_tenure = 0 for emp in employees: total_tenure += emp["tenure"] average_tenure = total_tenure / len(employees) print(f"Average tenure: {average_tenure:.2f} years")
When formatting a report for HR, clarity and organization are key. Use clear headings such as Employee Report or Departments to divide sections. Align numbers for readability and use consistent spacing. Consider breaking the report into logical parts: a title, a summary of total employees, a section listing departments with their respective employee counts, and a final section showing the average tenure. This structure ensures that your report is both informative and easy to read, making it valuable for stakeholders who rely on these insights for decision-making.
Swipe to start coding
Write a function that prints a formatted employee report using the provided list of employee dictionaries. The report must include the following sections:
- A title at the top of the report.
- The total number of employees.
- A list of departments with the count of employees in each.
- The average tenure of all employees, rounded to two decimal places.
Lösung
Danke für Ihr Feedback!
single