Question: 2.) Write a function called stop_light that determines whether a stop light should change color, and, if so, what color it should change to. It

2.) Write a function called stop_light that determines whether a stop light should change color, and, if so, what color it should change to. It takes two arguments. The value of the first will be either "green", "yellow", or "red". This represents the stop light's current color. The second parameter tells the function how long this color has been showing. If green has been showing longer than 60 seconds, return "yellow". If yellow has been showing longer than 5 seconds, return "red". If red has been showing longer than 55 seconds, return "green". If the color hasn't been showing long enough (e.g, green has been showing for 17 seconds), return the current color. Here are some examples of calling the function with different arguments. (The code executed is in blue, the value returned by the function is in green): stoplight ('green, 61) stop_light ('yellow', 5) stop_light ('yellow', 6) stop light('red', 12) stop light('red', 56) 'yellow yellow >'red >'red green
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
