Question: I am having trouble solving this python problem. Now that you have a traffic light program with different turtles for each light, perhaps the visiblitiy

I am having trouble solving this python problem. Now that you have a traffic light program with different turtles for each light, perhaps the visiblitiy /invisibility trick was not a good idea. If we watch the traffic lights, they turn on and off but when they are off they are still there, perhaps just a darker color. Modify the program so the lights don't disappear: they are either on or off. But when they're off, they're still visible.

Here is the code I have so far

import turtle

wn = turtle.Screen() wn.title("traffic light!") wn.bgcolor("lightgreen")

def draw_housing(): house = turtle.Turtle() house.pensize(3) house.color("black", "darkgrey") house.begin_fill() house.forward(80) house.left(90) house.forward(200) house.circle(40, 180) house.forward(200) house.left(90) house.end_fill()

draw_housing()

first = turtle.Turtle() first.hideturtle() first.penup() # Position first onto the place where the green light should be first.forward(40) first.left(90) first.forward(50) # Turn first into a big green circle first.shape("circle") first.shapesize(3) first.fillcolor("green") ##### draw_housing2()

second = turtle.Turtle() second.hideturtle() second.penup() # Position first onto the place where the green light should be second.forward(40) second.left(90) second.forward(120) # Turn first into a big green circle second.shape("circle") second.shapesize(3) second.fillcolor("yellow")

third= turtle.Turtle() third.hideturtle() third.penup() # Position first onto the place where the green light should be third.forward(40) third.left(90) third.forward(190) # Turn first into a big green circle third.shape("circle") third.shapesize(3) third.fillcolor("red")

# This variable holds the current state of the machine state_num = 0

def advance_state_machine1(): global state_num

if state_num == 0: # Transition from state 0 to state 1 state_num = 1 first.showturtle() second.hideturtle() third.hideturtle() elif state_num == 1: # Transition from state 1 to state 2 state_num = 2 first.hideturtle() second.showturtle() third.hideturtle() else: # Transition from state 2 to state 0 state_num = 0 first.hideturtle() second.hideturtle() third.showturtle()

wn.ontimer(advance_state_machine1, "5000")

advance_state_machine1()

wn.mainloop()

By the way the version of python I'm using is python 3.6.

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!