# Homework #2 problem #3 answer -- a variant # # Matt Bishop, Jan. 18, 2012 # ECS 10, Winter Quarter 2012 # we need the turtle module to use turtles import turtle import time # # now make the turtle and window # wn = turtle.Screen() # creates a playground for turtles matt = turtle.Turtle() # create a turtle, assign to matt # # read in the number of sides # try: # read in a positive integer n = int(input("How many sides do you want? ")) except: # opps . . . not an integer print("You must enter an integer that is at least 2") else: if n < 2: print("Please enter an integer that is at least 2") else: # set the angle to turn at each coner angle = 360/n # # draw the polygon for i in range(0,n): matt.forward(500/n) # draw the side matt.left(angle) # rotate the turtle # # clean up; hide the turtle and block matt.hideturtle() time.sleep(5) # wait 5 seconds finally: wn.bye() # close window