Back

Code Challenge: Traffic Light

Difficulty  

divider

Objective

Ask the user for a traffic light color and print what that light means.

Skills to Practice

  • Prompting a user for input
  • Comparing strings
  • Branching with if / elif / else
  • Formatting custom output

Tasks

  • Create a new Python program named cc-traffic-light.
  • Prompt the user to enter red, yellow, or green.
  • Display Go! for green, Prepare to stop! for yellow, and Stop! for red.
  • Add an else for anything that is not one of those three.
  • Useful trick: calling .lower() on the input makes GREEN, Green, and green all work.

Sample Output

Sample Output
Enter a traffic light color: green [Enter]
Go!

Commence Challenge