Sierpinski turtle triangle I am working through Programming Fundamentals with Python on Udacity. The assignment was to create a recursive triangle. I am happy with the output, but I am hoping for feedback on the actual construction of the program. Could I have done this in a more simple and concise way?

import turtle

def draw_polygon(a_turtle, length, sides):
    counter = 0
    while (counter &lt; sides):
        a_turtle.forward(length)
        a_turtle.right(360 / sides)
        counter = counter + 1

def draw_triangle(a_turtle, length):
    draw_polygon(a_turtle, length, 3)

def draw_fractal_triangle(a_turtle, length, depth):
    if (depth == 1):
        draw_triangle(a_turtle, length)
    else:
        for i in range(1,4):
            draw_fractal_triangle(a_turtle, length/2, depth-1)
            a_turtle.forward(length)
            a_turtle.right(120)

def draw():
    window = turtle.Screen()
    window.bgcolor("black")

    brent = turtle.Turtle()
    brent.shape("turtle")
    brent.color("yellow")

    length = 200
    brent.backward(length/2)
    draw_fractal_triangle(brent, length, 5)
    window.exitonclick()

draw()


```
Nice.  I only have three comments.


In draw_polygon() use a for loop rather than an explicit counter:

def draw_polygon(a_turtle, length, sides):
    for counter in range(sides):
        a_turtle.forward(length)
        a_turtle.right(360 / sides)

Add comments and/or docstrings.  These will help you when you look at the code in the future.

For these kinds of tasks I usually add a top level docstring with a description of the task.  Include a url to the problem if applicable.  For example at the top of the file:

'''Recursive implementation of Sierpinski Triangle

Assignment from Programming Fundamentals with Python on Udacity.
'''


For any function/method etc. that has an algorithm that isn't immediately obvious from the code, add a comment or docstring explaining what/how it's doing it.  For example, I would add a docstring to draw_recursive_triangle() to explain what the function is doing, any assumptions (does it matter which way the turtle is pointing?, are there min or max limits on length? are the triangles always equilateral?, etc.).
The functions might be useful in another program/assignment.  Rather than rewriting them, you could import this file as a library if you use a if __name__ == "__main__": guard like so:

if __name__ == "__main__":
    draw()


That way it runs the program if you execute the file, but not if you import it as a library