Untitled

 avatar
unknown
plain_text
a month ago
938 B
7
Indexable
# Connect the modules you need
from turtle import *
from time import sleep
from random import randint

# Create a "turtle" object, set the shape, color, and speed

t = Turtle()
t.color('red')
t.penup()
t.shape('turtle')
t.speed(10)
t.points = 0

# Define a rand_move() function to move the turtle to a random point
def rand_move():
   t.goto(randint(-200, 200), randint(-150, 150))
   
# Define a catch(x, y) handler function that will handle a click on the turtle
# (successful clicks are accumulated in the t.points property)
def catch(x, y):
   t.write('A!', font=('Arial', 14, 'normal'))
   t.points = t.points + 1
   rand_move()

# Create a subscription to the «click on the turtle» event
t.onclick(catch)
# Create a loop that runs as long as the t.points clicks are fewer than 3
while t.points < 3:
   sleep(1.5)
   rand_move()


t.write('You won!', font=('Arial', 16, 'bold'))
t.hideturtle()

Editor is loading...
Leave a Comment