Question

enter image description here

So I am trying to teach myself how to code using interactivepython.com

this is one of the exercises...

I have this so far:

import turtle

window = turtle.Screen()
window.bgcolor("lightgreen")

brandon = turtle.Turtle()
brandon.fillcolor('blue') 
brandon.pencolor('blue')
brandon.pensize(3)


def drawsq(t, s):
    for i in range(4):
        t.forward(s)
        t.left(90)

for i in range(1,180):
    brandon.left(360/i)
    drawsq(brandon, 50)

I have tried different ways of rotating the square, but I have not done it correctly. To me this looks like a square rotated x amount of times, right? Could someone please explain this to me?

Thank you!

I keep coming up with something like this enter image description here

Était-ce utile?

La solution

I think the issue has to do with how much you are rotating by. In your loop, you keep picking different angles to rotate each square. But those aren't angles from a fixed starting position, but rather from the position of the last rotation. This results in a bunch of squares at seemingly random orientations.

Try making your loop something like:

for _ in range(20):   # value is not used, it is not an angle, but the number of squares
    brandon.left(18)  # pick some fixed angle to turn by
    drawsq(brandon, 50)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top