Question: . Progam# 3 : Simple Traffic Light Simulator Write a program that simulates simple Traffic Light as follows. Imagine a pedestrian waiting at a traffic

. Progam#3: Simple Traffic Light Simulator
Write a program that simulates 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".
Asks the user to input the color of the traffic light (`"green"`,`"yellow"`, or `"red"`).
Asks the user if the "Walk" signal is `"on"` or `"off"`.
Decides and prints 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 use 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). Same applies of 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 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 combination.
3. Display a Menu and handle the case if the user type an invalid choice.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!