Answered step by step
Verified Expert Solution
Link Copied!

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 = 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions