Challenge: Identify High Turnover Departments
In your HR data analysis journey, you have learned how to work with dictionaries to store and process structured information, such as employee or department data. Iterating through a dictionary allows you to access each key-value pair, making it possible to examine or manipulate the data based on specific criteria. Conditional logic, such as using an if statement, helps you filter out only the information that meets certain requirements. This skill is essential when you want to identify trends or outliers—like departments with unusually high turnover rates.
1234567891011121314# Example: Identifying departments with turnover above a threshold department_turnover = { "Sales": 0.15, "Engineering": 0.08, "HR": 0.12, "Marketing": 0.09 } threshold = 0.10 for department, turnover in department_turnover.items(): if turnover > threshold: print(f"{department} has high turnover: {turnover:.0%}")
When presenting the results, it is helpful to format your output so that high-turnover departments stand out clearly. You can print each qualifying department on a new line, including both the department name and its turnover rate as a percentage. Using string formatting, such as f"{value:.0%}", will display the turnover rate in an easy-to-read percentage format, making your HR reports more professional and actionable.
Swipe to start coding
Write a function that prints the names and turnover rates of all departments with turnover above the given threshold.
- Iterate through each department and its turnover rate in the
department_turnoverdictionary. - For each department, check if the turnover rate is greater than
threshold. - If the turnover rate is above the threshold, print the department name and turnover rate as a percentage using string formatting.
Solução
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Can you explain how the string formatting works in this example?
What other criteria could I use to filter departments?
How can I modify the code to show departments with low turnover instead?
Incrível!
Completion taxa melhorada para 4.76
Challenge: Identify High Turnover Departments
Deslize para mostrar o menu
In your HR data analysis journey, you have learned how to work with dictionaries to store and process structured information, such as employee or department data. Iterating through a dictionary allows you to access each key-value pair, making it possible to examine or manipulate the data based on specific criteria. Conditional logic, such as using an if statement, helps you filter out only the information that meets certain requirements. This skill is essential when you want to identify trends or outliers—like departments with unusually high turnover rates.
1234567891011121314# Example: Identifying departments with turnover above a threshold department_turnover = { "Sales": 0.15, "Engineering": 0.08, "HR": 0.12, "Marketing": 0.09 } threshold = 0.10 for department, turnover in department_turnover.items(): if turnover > threshold: print(f"{department} has high turnover: {turnover:.0%}")
When presenting the results, it is helpful to format your output so that high-turnover departments stand out clearly. You can print each qualifying department on a new line, including both the department name and its turnover rate as a percentage. Using string formatting, such as f"{value:.0%}", will display the turnover rate in an easy-to-read percentage format, making your HR reports more professional and actionable.
Swipe to start coding
Write a function that prints the names and turnover rates of all departments with turnover above the given threshold.
- Iterate through each department and its turnover rate in the
department_turnoverdictionary. - For each department, check if the turnover rate is greater than
threshold. - If the turnover rate is above the threshold, print the department name and turnover rate as a percentage using string formatting.
Solução
Obrigado pelo seu feedback!
single