Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 EnumTrafficLightred 'yellow', 'green'
# interp. a traffic light is either red, yellow or green
# examples are redundant for enumerations
@typecheck
def fnfortrafficlighttl: TrafficLight:
# template based on Enumeration
if tl TrafficLight.red:
return
elif tl TrafficLight.yellow:
return
elif tl TrafficLight.green:
return
Design a function called producenextlight 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
producenextlight python function Function to design
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started