title: Python Turtle Recursion Tree
body: <p>I am suppose to write a program using python's turtle that creates a tree with levels. Below are some I/O's so you see what it is suppose to do. </p>
  
  <p><img src="https://i.stack.imgur.com/iQmNe.png" alt="enter image description here"></p>
  
  <p>My program works for the first case, but prints too many for the second case. The stipulations for this program are:</p>
  
  <ul>
  <li><p>must be recursive</p></li>
  <li><p>can only use the following turtle functions:</p>
  
  <pre><code>turtle.forward(100)     &lt;-- turtle goes forward 100 steps
  turtle.right(90)        &lt;-- turtle turns right 90 degrees
  turtle.penup()          &lt;-- turtle lifts its pen up off of the paper
  turtle.forward(100)     &lt;-- turtle goes forward 100 steps
  turtle.pendown()        &lt;-- turtle puts its pen down on the paper
  turtle.pencolor("red")  &lt;-- turtle uses red pen
  turtle.circle(100)      &lt;-- turtle draws circle of radius 100 
  turtle.pencolor("blue") &lt;-- turtle changes to blue pen (most other common colors work too!)
  turtle.forward(50)      &lt;-- turtle moves forward 50 steps
  turtle.xcor()           &lt;-- turtle returns its current x-coordinate
  turtle.ycor()           &lt;-- turtle returns its current y-coordinate
  </code></pre></li>
  </ul>
  
  <p>My Program:</p>
  
  <pre><code>import turtle
  
  def tree(length,n):
      """ paints a branch of a tree with 2 smaller branches, like an Y"""
      if length &lt; (length/n):
             return       # escape the function
      turtle.forward(length)        # paint the thik branch of the tree
      turtle.left(45)          # rotate left for smaller "fork" branch
      tree(length * 0.5,length/n)      # create a smaller branch with 1/2 the lenght of the parent branch
      turtle.right(90)         # rotoate right for smaller "fork" branch
      tree(length * 0.5,length/n)      # create second smaller branch
      turtle.left(45)          # rotate back to original heading
      turtle.backward(length)       # move back to original position
      return              # leave the function, continue with calling program
  </code></pre>