Python Forum
(turtle module) fonction calling an other fonction
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(turtle module) fonction calling an other fonction
#1
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 !
Reply
#2
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020