python,画图问题
怎么用python随机画出n条线段并获取端点坐标import turtle as t
import random
def random_position():
x = random.randint(-500, 500)
y = random.randint(-500, 500)
return x, y
if __name__ == "__main__":
t.setup(1000, 1000, 10, 10)
t.speed(0)
t.ht()
for _ in range(3):
p1, p2 = random_position(), random_position()
t.penup()
t.goto(p1)
t.pendown()
t.goto(p2)
print(f'Start point {p1}, End point {p2}')
t.done()
页:
[1]