Help With Programming in Python

Post » Sat Nov 15, 2014 6:01 pm

Hey Guys, I wrote this fractal program below which runs off a Scribbler robot that uses it to draw on the floor. When called, the value passed through the function determines how complex the fractal is. I want to see if I can shorten it though with just some loops instead of conditionals. Do you guys have any ideas how to proceed? Here is the code:

def fractal(int1, y=1):
if (int1 == 1):
forward(y/2)
else:
fractal((int1-1), y/3)
turnLeft(1, 0.825)
if (int1 == 1):
forward(y/2)
else:
fractal((int1-1), y/3)
turnRight(1, 0.825)
if (int1 == 1):
forward(y/1)
else:
fractal((int1-1), y/3)
turnLeft(1, 0.825)
if (int1 == 1):
forward(y/2)
else:
fractal((int1-1), y/3)
User avatar
candice keenan
 
Posts: 3510
Joined: Tue Dec 05, 2006 10:43 pm

Return to Othor Games