Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I can't figure out what variable to put in the replacement for wn towards the end of the code.

#-----import statements----

import turtle as trtl

#-----game configuration----

score1 = 0

score2 = 0

#-----initialize turtle-----

painter1 = trtl.Turtle()

painter1.goto(-100, 0)

painter1.shape("circle")

painter1.fillcolor("red")

painter1.shapesize(3)

painter2 = trtl.Turtle()

painter2.goto(100,0)

painter2.shape("square")

painter2.fillcolor("blue")

painter2.shapesize(3)

score_writer = trtl.Turtle()

score_writer.speed(0)

score_writer.penup()

score_writer.goto(50,-60)

score_writer.setheading(-180)

score_writer.pendown()

x = 0

while (x < 2):

  score_writer.forward(100)

  score_writer.left(-90)

  score_writer.forward(25)

  score_writer.left(-90)

  x += 1

score_writer.ht()

score_writer1 = trtl.Turtle()

score_writer1.penup()

score_writer1.goto(20,-64)

score_writer1.ht()

score_writer2 = trtl.Turtle()

score_writer2.penup()

score_writer2.goto(-30,-64)

score_writer2.ht()

font_setup = ("Arial", 20, "normal")

timer = 5

counter_interval = 1000

timer_up = False

counter =  trtl.Turtle()

counter.penup()

counter.goto(-5,-76)

counter.ht()

#-----game functions--------

def update_score_for_painter1(x,y):

    global score1

    score1 += 1

    score_writer1.clear()

    score_writer1.write(score1, font = font_setup)

def update_score_for_painter2(x,y):

    global score2

    score2 += 1

    score_writer2.clear()

    score_writer2.write(score2, font = font_setup)

timer = 30

def countdown():

  global timer, timer_up

  counter.clear()

  if timer <= 0:

    counter.write("Time's Up", font=font_setup)

    timer_up = True

  else:

    counter.write("Timer: " + str(timer), font=font_setup)

    timer -= 1

    counter.getscreen().ontimer(countdown, counter_interval) 

#---------events----------

painter1.onclick(update_score_for_painter1)

painter2.onclick(update_score_for_painter2)

wn.ontimer(countdown, counter_interval)

trtl.done()

1 Answer

0 votes
by (36.8k points)

This is working on repl.it

screen = trtl.getscreen()

screen.ontimer(countdown, counter_interval)

Learn Python for Data Science Course to improve your technical knowledge. 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...