← Python from Scratch Lesson 24 of 78 · 5 XP

Warm-up: traffic light warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

When there are more than two options, put elif ("else if") between if and else. Python checks the conditions from top to bottom and runs the first block that fits:

if color == "red":
    print("stop")
elif color == "yellow":
    print("wait")

Task. Read a traffic-light colour and print: red → stop, yellow → wait, green → go.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.