I want to create an output like this: 
I have to use recursion.
So far , This is what my code looks like:
from turtle import *
def drawFlake(length,depth):
fd(length)
input("first line done")
if depth>0:
left(60)
drawFlake(length/3,depth-1)
input("1")
left(120)
drawFlake(length/3,depth-1)
input("2")
left(120)
drawFlake(length/3,depth-1)
input("3")
left(120)
drawFlake(length/3,depth-1)
input("4")
left(120)
left(180)
#drawFlake(length/3,depth-1)
input("1")
left(120)
drawFlake(length/3,depth-1)
input("THIS IS THE LAST")
left(60)
left(180)
fd(length)
drawFlake(100,3)
And this produces an output like this(here, N =3)
The issue is that long line at the left. There should be no long line. Instead, there should be another flake pattern
What Am I doing wrong ?
EDIT::
This is something better that I managed to come up with. But it is still not perfect :
def doFigure(length,depth):
left(120)
fd(length)
if depth>1:
doFigure(length/3,depth-1)
bk(length)
right(60)
fd(length)
if depth>1:
doFigure(length/3,depth-1)
bk(length)
right(60)
fd(length)
if depth>1:
doFigure(length/3,depth-1)
bk(length)
right(60)
fd(length)
if depth>1:
doFigure(length/3,depth-1)
bk(length)
right(60)
fd(length)
if depth>1:
doFigure(length/3,depth-1)
bk(length)
right(60)
fd(length)
if depth == 3:
doFigure(length/3,depth-1)
bk(length)
right(180)
Note the 5th last line. I am having to hard code the value 3 to get the correct value.
After a few days , I came up with a solution. This is definitely not the best way to go about it(I would be glad if more people posted their solutions), but It does show the output EXACTLY like in my original picture.
def makeFlake(length,depth,isRoot=True):
"""
This function draws the flakes. To draw the smaller flakes, this function is called recursively
:param length: the length of the biggest flake's branch
:param depth: The number of smaller flakes to draw
:param isRoot: Draw an extra branch if the value is true. Note that true is the default value.
"""
if depth>0:
forward(length)
makeFlake(length // 3, depth - 1,False)
backward(length)
left(60)
forward(length)
makeFlake(length // 3, depth - 1,False)
backward(length)
left(60)
forward(length)
makeFlake(length // 3, depth - 1,False)
backward(length)
left(60)
forward(length)
if isRoot == True:
makeFlake(length // 3, depth - 1,False)
backward(length)
left(60)
forward(length)
makeFlake(length // 3, depth - 1,False)
backward(length)
left(60)
forward(length)
makeFlake(length // 3, depth - 1,False)
backward(length)
left(60)