gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
Write me a python function to control my light
- User
Write me a python function to control my light
- Assistant
Here's a Python function that acts as a simple model for controlling a light. It assumes that the light has two states: "ON" and "OFF". You can control the light by calling this function with the desired action as an input.
pythondef control_light(action): # Define the available actions available_actions = ('ON', 'OFF') # Check if the action is valid if action not in available_actions: print("Invalid action. Please use 'ON' or 'OFF'.") return # Perform the action if action == 'ON': print("Turning the light ON.") elif action == 'OFF': print("Turning the light OFF.") else: # This should never happen if action is valid print("Error: Unknown action")You can use this function like this:
python