0% found this document useful (0 votes)
8 views

Code Pal Result

Uploaded by

ssitporto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Code Pal Result

Uploaded by

ssitporto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

class ServiceSchedule:

"""
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

def create_schedule(self, hour: int, employee_name: str):


"""
Creates a service schedule entry for a specific hour with an employee's
name.

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

def update_schedule(self, hour: int, employee_name: str):


"""
Updates the service schedule entry for a specific hour with a new
employee's 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'}")

# Example of using the ServiceSchedule class:

# Initialize a service schedule


schedule_manager = ServiceSchedule()

# Create some schedule entries


schedule_manager.create_schedule(8, "Alice")
schedule_manager.create_schedule(16, "Bob")
schedule_manager.create_schedule(20, "Charlie")

# Display the current schedule


schedule_manager.display_schedule()

# Update a schedule entry


schedule_manager.update_schedule(16, "David")

# Display the updated schedule


schedule_manager.display_schedule()

You might also like