Python:
class LEDBank:
def __init__(self, num_leds):
self.num_leds = num_leds
self.leds = [False] * num_leds
def turn_on(self, index):
if 0 <= index < self.num_leds:
self.leds[index] = True
print(f"LED {index + 1} turned on.")
else:
print("Invalid LED index.")
def turn_off(self, index):
if 0 <= index < self.num_leds:
self.leds[index] = False
print(f"LED {index + 1} turned off.")
else:
print("Invalid LED index.")
def display(self):
print("Current LED status:")
for i in range(self.num_leds):
print(f"LED {i + 1}: {'On' if self.leds[i] else 'Off'}")
# Example usage:
bank = LEDBank(5)
bank.turn_on(2)
bank.turn_on(4)
bank.display()
bank.turn_off(2)
bank.display()
