>>    




Homework Assignment

CS 121 (CS1)

Homework 3   Due Monday, February 17, 2014
  1. Turtle graphics [c]

    1. midpoint -- Write a program using Turtle Graphics that draws a line segment then stamps a circle at the midpoint of that line segment. Submit your answer as a screenshot that shows both your code in idle3 and the drawing window displaying the image. Your final image should look something like this:

      Notes:




  2. Python3 modules

    1. -- Python Modules chapter problems at end of chapter: 2[H]
      ([H] means to write out the solution on paper and submit in class or in grader box.)

  3. More turtle graphics

    1. -- Python Turtle Graphics chapter problems at end of chapter: 2[H], 4, 6, 8[H], 10, 12[H]
      • The problems marked [H] should be written out on paper and submitted in class.

      • The other problems are short programs. Submit these via email to cs1b-graders@stolaf.edu (copying and pasting your code into an email is sufficient; screenshots not needed for these problems).

      Hints:
      Problem 6
      • After you input the values you will need (number of sides, length of sides, colors), you will need to use turtle graphics to draw the polygon. First move forward by the length of a side, then turn, then draw again, then turn, etc., until all sides have been drawn.

      • Use a for loop to draw the correct number of sides.

      • You can turn your turtle either right or left, as long as you always turn the same way while drawing your polygon. The amount to turn (whichever direction you choose) is 360/N, where N is the desired number of sides. For example, to draw a regular 4-sided polygon (i.e., a square), the amount of the turn should be 360/4 = 90.

      Problem 8
      • The point of this problem is to look at the Python3 code and predict what the turtle will draw, sketching your prediction on paper, then to press "Run" to check your prediction. To see the Python3 code, click on "Show/Hide code."

        In case it's helpful, this is the code that should be shown when you click on "Show/Hide code":

            import turtle
            wn = turtle.Screen()
            tess = turtle.Turtle()
            tess.right(90)
            tess.left(3600)
            tess.right(-90)
            tess.left(3600)
            tess.left(3645)
            tess.forward(-100)
        

      • Hint about those large left turns: The argument for left() is measured in degrees, and 360 degrees moves all the way around a circle, resulting in the turtle pointing in the same direction as it had before the 360-degree turn. It is as if the direction never changed.

        Use that fact to figure out what turtle direction would result after a 3600 degree turn.

      __________
      _____

  4. Reading