# Python----Draw a square and inscribed circle, enter the total number of points, so that the points are randomly and evenly distributed in the square and circle ()

2022-11-08 07:20:04

# turtle.tracer(1000) and turtle.update(): Speed ​​up the drawing, refresh every 1000 times, otherwise there will be a drawing process (slower)

``import random,turtle,math#turtle.goto(x,y) turtle.dot(5), the side length is 800n=eval(input())#Enter the total number of pointsturtle.tracer(1000)turtle.update()#Speed ​​up the painting, refresh once every 1000 times, if not, there will be a painting processturtle.pensize(1)turtle.pencolor("blue")turtle.penup()turtle.goto(-400,-400)turtle.pendown()for i in range(4):turtle.fd(800)turtle.left(90)#'To the leftturtle.fd(400)#straightforward400pxturtle.pencolor("red")turtle.circle(400)for i in range(n):x,y=random.random()*400,random.random()*400signx,signy=random.choice("+-"),random.choice("+-")turtle.penup()#Randomly generate positive and negative coordinatesturtle.goto(eval(signx+str(x)), eval(signy+str(y)))if math. sqrt(eval(signx+str(x))**2+eval(signy+str(y))**2)<=400:#Distinguish inside the circle (red) and outside the circle (blue)turtle.pencolor("red")else:turtle.pencolor("blue")turtle.pendown()turtle.dot(10)turtle.done()``