Python Forum

Full Version: (turtle module) fonction calling an other fonction
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, so I am learning python , a lot of fun but I am now stuck

Let me explain:

I am working with the turtle module and I have 2 void fonctions : draw_triangle_equilateral(turtle,size) and draw_polygone(turtle,number_sides,size)

The 2 works well but my question is :

How can a have the triangle fonction to call the polygone fonction to draw a equilateral triangle ?

I don't understand how we can mix those fonctions to work togheter.

If this can help, I will copy-paste the 2 fonctions here,




def draw_triangle_equi(t,sz):
for i in range(3):
t.forward(sz)
t.left(120)


def draw_poly(t,n,sz):
for i in range(n):
t.forward(sz)
t.left(360/n)


Thanks a lot in avdance and greetings from Quebec !
Use variable names that are easy for anyone to understand. I had to read your code to understand what t, n and sz were supposed to represent.
def draw_triangle_equi(turtle, length):
    draw_poly(turtle, 3, length)

def draw_poly(turtle, sides, length):
    for i in range(n):
        turtle.forward(length)
        turtle.left(360/sides)
Also, when you post code make sure it is wrapped in python tags