我如何在 python 中通过海龟绘制一系列(例如:5)平行线?
def parallel_lines(number):
#Help me write the body of the function
#number is the number of lines for drawing
试试这个代码
from turtle import *
#we make an object from class Turtle
alex=Turtle()
def parallel_lines(number):
#number is number of lines
with_s=alex.window_width()
height_s=alex.window_height()
alex.setheading(90)
alex.pu()
#for fill all screen and equall distance below line needed
alex.setposition(with_s/-2,height_s/-2)
for i in range(1,number+1):
alex.pd()
alex.fd(height_s)
alex.pu()
alex.setposition(with_s/-2+i*(with_s/(number-1)),height_s/-2)
parallel_lines(5)
output
边缘是 2 行,屏幕是 3 行