我解决了。如果将来有人遇到这个问题,可以采用以下解决方案:#Function that draws a triangle with n dots as base
def drawTriangularSeries(myTurtle, n):
sideLength = 10
x = 0 - sideLength
y= 200
myTurtle.penup()
myTurtle.goto(x, y)
for i in range(n+1):
y = 200
myTurtle.goto(x, y)
for j in range(i):
myTurtle.goto(x, y)
myTurtle.dot()
y += sideLength
myTurtle.forward(sideLength)
x += sideLength
# Function that draws a series of triangles with dPS as base #
def drawTriangle(myTurtle, dotsPerSide, startX, startY):
sideLength = 10
x = startX - sideLength
y = startY
myTurtle.penup()
myTurtle.goto(x, y)
for i in range(dotsPerSide):
for j in range(i + 2):
y = startY
myTurtle.goto(x, y)
for k in range(j):
myTurtle.goto(x, y)
myTurtle.dot()
y += sideLength
myTurtle.forward(sideLength)
x += sideLength
myTurtle.hideturtle()