That program will work exactly as you have programmed it.
The questions then become: What do you expect it to do? How do you expect it to function? Does it meet those expectations?
The hardest part of any automation project is to define what you want. Do that first -- before you ever start writing code. Do a flow chart, an outline, a process narrative... whatever it takes to DEFINE your project. This includes process steps and the transitions between each of those steps, how the process starts/stops, how the operator interfaces with the system, how faults are detected and indicated and cleared, etc.
Then figure out what IO you will need to accomplish that.
Then start writing code.
I ~know~ what your stoplight is supposed to do (I've been driving for nearly 40 years), but define YOUR system first. THEN we can help you.
Until then, your code will perform exactly as you've written it, but I don't know what you intend it to do.
And, like Ken said, document it. Without proper documentation, it is extremely difficult to evaluate code for any purpose...