Question: Here is a data definition for a data type called TrafficLight. TrafficLight = Enum ( ' TrafficLight ' , [ ' red ' , 'yellow',

Here is a data definition for a data type called TrafficLight.
TrafficLight = Enum('TrafficLight',['red', 'yellow', 'green'])
# interp. a traffic light is either red, yellow or green
# examples are redundant for enumerations
@typecheck
def fn_for_traffic_light(tl: TrafficLight)->...:
# template based on Enumeration
if tl == TrafficLight.red:
return ...
elif tl == TrafficLight.yellow:
return ...
elif tl == TrafficLight.green:
return ...
Design a function called produce_next_light that takes a TrafficLight and produces the next TrafficLight. Here, we'll assume that the traffic light has the expected behaviour of transitioning from red to green to yellow to red, etc.
Note that the data definition we provided above does not solve the problem. The "function" defined there is actually a template function: it's the "skeleton" of what any function that operates on a TrafficLight will likely do, but without any details filled in.
To use a data definition, put it in a cell above the one where you're designing your function. Do not edit it, as that is not required to solve this problem. To use a template function (to design a function that takes a parameter whose type is from that data definition), you copy and paste it at the templating stage of the How to Design Functions recipe.
Name Type Description
produce_next_light python function Function to design

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!