使用海龟绘图。输入多个点,将这些点都两两相连。
import turtle
import random
turtle.color('red')
turtle.speed(5)
turtle.penup()
li=[]
n = int(input('请输入点的个数:'))
def draw_line(n):
for i in range(n):
x = random.uniform(-200, 200)
y = random.uniform(-200, 200)
li.append((x, y))
print(li)
a=1
for p in li:
turtle.goto(p)
turtle.pendown()
for q in li[a:n]:
turtle.goto(q)
turtle.penup()
turtle.goto(p)
turtle.pendown()
a+=1
turtle.hideturtle()
turtle.done()
draw_line(n)
print('绘图结束')