1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Rep Power

    Python programming - turtleworld

    Hello.. im a beginner at python

    I want to draw a sierpenski triangle with depth 5.

    Can someone help me please? So far ive drawed a triangle..

    I know i have to use recursive loops but i find this hard to understand .. my idea was to start with the little trinangle and go out to bigger triangles and so on.

    so far ive have made:

    from swampy.TurtleWorld import *

    angle = 60
    def triangle(t, length, n):
    for i in range(3):
    fd(t, length)
    lt(t, 180/n)
    lt(t, 180/n)

    def depth(n):
    if n == 0:

    world = TurtleWorld()
    bob = Turtle()
    bob.delay = 0.1
    triangle(bob, 10, 60)

  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    1) Use the turtle module supplied with python rather than some custom thing few people have.

    2) I can find examples of Sierpinski triangle turtle programs in python (except that it doesn't matter since the logo calls to turtle should be easily similar) on the internet. So can you.

    3) Recursive algorithms can be expressed without recursion. Your statement that you need recursion is false.

    4) Your triangle function needs 3 arguments yet you try to call it without arguments in your function depth.

    Good luck.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo