I'm trying to make a dot pop up on a screen at a random point. I set the screen boundaries, but when I use those boundaries to choose a random number, the number is sometimes too large and does not show up on the screen. What can I do to fix this? My code is below. import turtle import random import time
# screen
screen = turtle.Screen()
screen.title("Moving Block")
screen.bgcolor("white")
screen.setup(width=1920, height=1080)
width = 1920
height = 1080
# dot
dot = turtle.Turtle()
dot.shape("circle")
dot.color("black")
dot.penup()
dot.turtlesize(0.5,0.5)
# 2 seconds rest before beginning
time.sleep(2)
# display dot
counter = 0
while counter < 5:
dot.hideturtle()
# position
time.sleep(1)
x = random.randrange(int(width/2*-1), int(width/2))
y = random.randrange(int(height/2*-1), int(height/2))
dot.setpos(x,y)
print(x, y)
dot.showturtle()
time.sleep(3)
counter += 1