(turtle module) fonction calling an other fonction - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: (turtle module) fonction calling an other fonction (/thread-30460.html) |
(turtle module) fonction calling an other fonction - frankjazz89 - Oct-21-2020 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 ! RE: (turtle module) fonction calling an other fonction - deanhystad - Oct-21-2020 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 |