Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. t

image text in transcribed

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. t 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): stop_light ('green', 61) yellow stop_light('yellow',5) ->'yellow stop_light('yellow', 6) -->red stop_light('red', 12)->'red stop_light ('red', 56) >'green

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

How do we organise for international logistics?

Answered: 1 week ago

Question

What are the logistics implications of internationalisation?

Answered: 1 week ago