← back to unit
Easy
# breaking it down easy
Traffic Light
Green, then yellow, then red, then green again — forever. What color is it at second t? 🚦
You get the lengths of green, yellow, and red (in seconds), and a time t (seconds after a green began, 0-based, possibly many cycles later). Print the color showing at second t.
Example:
Input: green = 10, yellow = 3, red = 7, t = 12
Output: yellow
One full cycle is 20 seconds. Second 12 comes after the first 10 (green) seconds but within the next 3 (yellow) seconds — so the light is yellow.
💡 need a hint?
brk-traffic-light.py🔒 given lines are locked — write your code in between
loading...