Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursion with the turtle module (Python 3.1)
    primarykey
    data
    text
    <p>I have a homework assignment that I just cant grasp. It makes no sense to me, and I dont even know if im going in the right direction at this point. </p> <p>here is my code so far:</p> <pre><code>import turtle def draw_rectangle(center_x, center_y, width, height, myTurtle): myTurtle.penup() myTurtle.goto(center_x - width/2, center_y - height/2) myTurtle.pendown() myTurtle.goto(center_x - width/2, center_y + height/2) myTurtle.goto(center_x + width/2, center_y + height/2) myTurtle.goto(center_x + width/2, center_y - height/2) myTurtle.goto(center_x - width/2, center_y - height/2) def smallerRec(width, height, level, myTurtle): rectangle_art( width/2, -height/2, width/2 , height/2, level-2, myTurtle) rectangle_art(-width/2, height/2, width/2 , height/2, level-2, myTurtle) rectangle_art(-width/2, -height/2, width/2 , height/2, level-2, myTurtle) rectangle_art( width/2, height/2, width/2 , height/2, level-2, myTurtle) def smallerRec3(width, height, level, myTurtle): bottom_y = 25 top_y = 75 left_x = 50 right_x = 150 rectangle_art( right_x, top_y, width/level , height/level, level-3, myTurtle) rectangle_art( right_x, bottom_y, width/level , height/level, level-3, myTurtle) rectangle_art( left_x, top_y, width/level , height/level, level-3, myTurtle) rectangle_art( left_x, bottom_y, width/level , height/level, level-3, myTurtle) def rectangle_art(center_x, center_y, width, height, level, myTurtle): if (level &lt;= 1): draw_rectangle(center_x, center_y, width, height, myTurtle) elif(level == 2): draw_rectangle(center_x, center_y, width, height, myTurtle) smallerRec(width, height, level, myTurtle) elif(level == 3): draw_rectangle(center_x, center_y, width, height, myTurtle) smallerRec (width, height, level, myTurtle) smallerRec3(width, height, level, myTurtle) def main(): myTurtle = turtle.Turtle() myWindow = turtle.Screen() rectangle_art(0, 0, 200, 100, 3, myTurtle) myWindow.exitonclick() main() </code></pre> <p>and this is the output of that code: <a href="http://puu.sh/5j491.png" rel="nofollow noreferrer">outout of the code above http://puu.sh/5j491.png</a></p> <p>and here is what it should look like:</p> <p><a href="http://puu.sh/5j4ds.png" rel="nofollow noreferrer">the assignment http://puu.sh/5j4ds.png</a></p> <p>Am I headed in the right direction, in terms of recursion?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload