Traffic Light Simulator (match-case)
Easypython
Read a traffic light color and print the correct action, using Python's match-case statement.
red->Stopyellow->Get Readygreen->Go- anything else ->
Invalid signal
Approach: this is a direct application of match-case from this topic — one case per color, plus a case _: default for anything unrecognized.
Input: One line: a color name ("red", "yellow", or "green").
Output: One line: the matching action.
Example 1
Input
yellow
Output
Get Ready
- The input is a single word, any case.
Hint 1
Normalize the input first (.strip().lower()) so "Red" and "red" both match.
Hint 2
Use match color: with one case per color string.
Hint 3
Add case _: as the default for anything that isn't red, yellow, or green.
match color: compares the (lower-cased, stripped) input against each case in order — "red" prints Stop, "yellow" prints Get Ready, "green" prints Go, and case _: catches anything else and prints Invalid signal.