Pythonでタートルで一連の平行線(ex: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 ライン