Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Generate Employee Report | Reporting and Insights for HR
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for HR Specialists

bookChallenge: 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.

123456789101112131415161718192021222324252627
employees = [ {"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")
copy

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.

Opgave

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øsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 3
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Can you show me how to format the output as a well-structured HR report?

How can I add a summary of total employees to the report?

Can you explain how to align the numbers for better readability in the report?

close

bookChallenge: Generate Employee Report

Stryg for at vise menuen

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.

123456789101112131415161718192021222324252627
employees = [ {"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")
copy

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.

Opgave

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øsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 3
single

single

some-alt