Program #3: Simple Traffic Light Simulator
Write a program that simulates a simple Traffic Light as follows:
- Imagine a pedestrian waiting at a traffic light. The pedestrian must decide whether it's safe to cross based on the color of the traffic light and whether a "Walk" signal is on or off. The traffic light can be "green", "yellow", or "red", and the "Walk" signal can be "on" or "off".
- Ask the user to input the color of the traffic light (`"green"`, `"yellow"`, or `"red"`).
- Ask the user if the "Walk" signal is `"on"` or `"off"`.
- Decide and print out what the pedestrian should do: `"Wait"`, `"Get Ready"`, or `"Cross"`.
- Rules:
1. If the traffic light is green and the "Walk" signal is on, print `"Cross"`.
2. If the traffic light is green and the "Walk" signal is off, print `"Wait"`.
3. If the traffic light is yellow, regardless of the "Walk" signal, print `"Get Ready"`.
4. If the traffic light is red, regardless of the "Walk" signal, print `"Wait"`.
5. If the user types an invalid input, display an ‘Input Error message’.
- Hints:
1. Use Boolean expressions with `and`, `or` to combine conditions.
2. Ensure the program handles different inputs robustly, including case sensitivity for the inputs (e.g., "Green", "green", "GREEN" should all be treated the same). The same applies to ‘on’ & ‘off’ (On, ON, on – Off, OFF, off).
- Use the .lower() to convert all to lower case!
- .lower() explained:
- color = input(‘enter color: ‘).lower() will convert whatever is typed to lower case. If the user types GReeN, it will be converted to green. This way, you only have to compare the choice/color with ‘green’ instead of trying all possible lower/uppercase combinations.
- Display a Menu and handle the case if the user types an invalid choice.