Traffic light

Define a function traffic_light that receives a color and returns:

'stop' if the color is red

'slow down' if the color is yellow

'go' if the color is green

Examples:

>>> traffic_light('red')
'stop'
>>> traffic_light('yellow')
'slow down'
>>> traffic_light('green')
'go'

Test Cases

test green light - Run Test

def test_green_light():
    assert traffic_light('green') == 'go'

test red light - Run Test

def test_red_light():
    assert traffic_light('red') == 'stop'

test yellow light - Run Test

def test_yellow_light():
    assert traffic_light('yellow') == 'slow down'

Solution 1

def traffic_light(color):
    if color == 'red':
        return 'stop'
    elif color == 'yellow':
        return 'slow down'
    elif color == 'green':
        return 'go'
def traffic_light(color): pass