Club Activity Schedule
You are helping a school club manage the availability of its members to schedule activities. Each member has a list of available time slots (hours in the day), and your task is to analyze this data to:
- Identify which members are available at specific times.
- Find common times when multiple members are free.
- Detect members who are often unavailable.
- Prepare a suggestion for the best time slot based on member availability.
To do this, you will write a script using multiple functions, each solving a part of the problem. These functions will call each other to accomplish the overall goal.
Exercises
Write a function, get_common_times, that takes a dictionary, members, where each value is
a set of available hours, and returns a set of hours when all members are available. Example:
>>> members = {'Alice': {9, 10, 14}, 'Bob': {10, 14, 15}, 'Dan': {10, 14}}
>>> get_common_times(members)
{10, 14}
Write a function, members_available_at, that takes a dictionary, members,
and an integer, hour, and returns a set of member names who are available at that hour.
Example:
>>> members = {'Alice': {9, 10, 14}, 'Bob': {10, 14, 15}, 'Dan': {10, 14}}
>>> members_available_at(members, 10)
{'Alice', 'Bob', 'Dan'}
Write a function, least_available_members that takes a dictionary, members,
and returns a list of member names who have the fewest available hours. Example:
>>> members = {'Alice': {9, 10, 14}, 'Bob': {10, 14, 15}, 'Dan': {10, 14}}
>>> least_available_members(members)
['Dan']
Write a function, suggest_best_time, that takes a dictionary, members,
and returns the hour when the most members are available.
If there is a tie, return the earliest hour. Example:
>>> members = {'Alice': {9, 10, 14}, 'Bob': {10, 14, 15}, 'Dan': {10, 14}}
>>> suggest_best_time(members)
10
Write a function, print_availability_report, that takes a dictionary, members
and prints a complete availability report. It should:
- Print the hours when all members are available
- Print who is available at 10am
- Print the least available members
- Print the best suggested hour for the activity
Example:
>>> members = {'Alice': {9, 10, 14}, 'Bob': {10, 14, 15}, 'Dan': {10, 14}}
>>> print_availability_report(members)
Common time slots for all members: 10, 14
Members available at 10am: 'Alice', 'Bob', 'Dan'
Least available members: 'Dan'
Best suggested hour for activity: 10