Question 1
Write a function traffic_signal(vehicle_type, signal, emergency) that tells a road user what to do.
- If
emergencyisTrueandvehicle_typeis"ambulance", return"Proceed Carefully". - Otherwise it depends on
signal:"red": return"Stop"."yellow": return"Slow Down"."green": return"Cross"ifvehicle_typeis"pedestrian", and"Go"for any other vehicle type.
- For any other
signal, return"Invalid Signal".
NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition.
Example
traffic_signal("car", "red", False) -> 'Stop'
traffic_signal("pedestrian", "green", False) -> 'Cross'
Your task
Implement this function:
def traffic_signal(vehicle_type: str, signal: str, emergency: bool) -> str:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: vehicle_type, signal, emergency.
Example
Input
"car"
"red"
False
Output
'Stop'