Skip to content

Instantly share code, notes, and snippets.

@naren345
Created April 23, 2025 22:15
Show Gist options
  • Save naren345/e42f858e727fe79770511f8a3805b51d to your computer and use it in GitHub Desktop.
Save naren345/e42f858e727fe79770511f8a3805b51d to your computer and use it in GitHub Desktop.
import turtle, time, random
# Set up the turtle screen
turtle.hideturtle()
turtle.turtles()
turtle.title("Red Light Green Light Game")
turtle.bgcolor("maroon")
turtle.color("gold")
# Function to display lights at random intervals
def random_lights():
for _ in range(10): # Loop for a fixed number of light changes
# Red light with "Stop" message
turtle.dot(1000, "red")
turtle.penup()
turtle.goto(0, -50) # Move below the light
turtle.color("white")
turtle.write("Stop", align="center", font=("Arial", 50, "bold"))
time.sleep(random.uniform(2, 5)) # Random interval between 2 to 5 seconds
turtle.clear() # Clear the "Stop" message
# Green light with "Go" message
turtle.dot(1000, "green")
turtle.penup()
turtle.goto(0, -50) # Move below the light
turtle.color("white")
turtle.write("Go", align="center", font=("Arial", 50, "bold"))
time.sleep(random.uniform(2, 5)) # Random interval between 2 to 5 seconds
turtle.clear() # Clear the "Go" message
# Run the game
random_lights()
# Display "Game Over" message
turtle.dot(1000, "red")
turtle.penup()
turtle.goto(0, -50)
turtle.color("white")
turtle.write("Game Over", align="center", font=("Arial", 50, "bold"))
turtle.done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment