"""File: draw_polygon_rec.py Purpose: Draw a regular polygon (i.e., all sides have same length) Run: python draw_polygon_rec Input: n = number of sides length = sidelength Output: Regular polygon drawn from current position of turtle Note: This version uses recursion """ from TurtleWorld import * def draw_polygon(t, length, n, degrees): """Draw a regular polygon with n sides and sidelength length using turtle t """ if n < 1: return else: fd(t, length) lt(t, degrees) draw_polygon(t, length, n-1, degrees) # Program start here world = TurtleWorld() # Create an instance of TurtleWorld -- i.e, a window bob = Turtle() # Create an instance of a Turtle n = int(raw_input("How many sides does the polygon have?\n ")) length = int(raw_input("How long is each side?\n ")) degrees = 360.0/n draw_polygon(bob, length, n, degrees) wait_for_user()