Red Light, Green Light π¦
Now you write the choice yourself! A traffic light tells cars when to go and when to stop.
You can drag the blocks in (in order) instead of typing, or tap the hint to fill
it in step by step. Remember: each line after the : is indented 4 spaces.
if color == "green":
return "go"
else:
return "stop"
We use == (two equals signs) to ask "is it exactly equal?"
Your task
Write light(color). If color is exactly "green", return "go".
Otherwise, return "stop".
β‘ 30 XP
π§± Code blocks
Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.
solution.pyRuns in your browser (Pyodide)
Loading editorβ¦
Tests3 to pass
"green" -> "go"
"red" -> "stop"
"yellow" -> "stop"
Run your code to check these.