Code Pal Result
Code Pal Result
"""
A class to manage service schedules where employees work in 8-hour shifts over
a 24-hour period.
This class provides functionality to create, update, and display service
schedules.
Attributes:
- schedule (list): A list to store the service schedule for each hour of the
day.
"""
def __init__(self):
"""
Constructs a new ServiceSchedule instance with an empty schedule.
"""
self.schedule = [None] * 24 # Initialize the schedule with 24 slots for
each hour
Parameters:
- hour (int): The hour of the day (0-23) for which the schedule entry is
being created.
- employee_name (str): The name of the employee assigned to the shift.
Returns:
None
Raises:
- ValueError: If the hour is not in the valid range (0-23).
"""
if hour < 0 or hour > 23:
raise ValueError("Hour should be between 0 and 23.")
self.schedule[hour] = employee_name
Parameters:
- hour (int): The hour of the day (0-23) for which the schedule entry is
being updated.
- employee_name (str): The new name of the employee assigned to the shift.
Returns:
None
Raises:
- ValueError: If the hour is not in the valid range (0-23) or if there is
no existing entry to update.
"""
if hour < 0 or hour > 23:
raise ValueError("Hour should be between 0 and 23.")
if self.schedule[hour] is None:
raise ValueError("No existing entry to update for this hour.")
self.schedule[hour] = employee_name
def display_schedule(self):
"""
Displays the current service schedule for all hours of the day.
Returns:
None
"""
for hour, employee_name in enumerate(self.schedule):
print(f"Hour {hour}: {employee_name if employee_name else 'No employee
scheduled'}")