MONT 105S, Spring 2009

Home | | Course Schedule | | Assignments | | Lecture Notes

Laboratory 2
Due at the end of today's class

Problem #1.
Write a Python program that asks the user for a size and uses a turtle to draw a square with a side length of that size. To use a turtle, first import the turtle class using the line:

This should be the first line of your program (after your program prologue comments with your name, date, assignment, class and purpose of the program).

Next you should prompt for and read in the size of the square.

Next, create a turtle object using the statement:

Use the forward(distance) and right(angle) turtle methods to draw a square. For example, to turn the turtle right by 90 degrees, use the statement: You should make your turtle end up in its original starting position and facing the same way as it started.

Problem #2.
Write a Python program that asks the user if they want to draw an X or an O.

If the user enters "X", your program should use a turtle object to draw an X.

If the user enters "O", your program should use a turtle object to draw an O.

If the user enters anything else, your program should print:

The following decision tree diagrams how the program should run:

The following Python code will draw an X:

    yertle.up( )
    yertle.goto(-50, 50)
    yertle.down( )
    yertle.right(45)
    yertle.forward(141)
    yertle.up( )
    yertle.goto(-50, -50)
    yertle.down( )
    yertle.left(90)
    yertle.forward(141)
The following Python code will draw an O:
    yertle.up( )
    yertle.goto(0, -50)
    yertle.down( )
    yertle.circle(50)
Use a conditional to determine what to draw.

What To Turn In.
A printed listing of each lab program. Be sure that your name is in the program prologue's comment section of EACH program.

Reminder.
Be sure to save a copy of each program on your P:\ drive.
You are responsible for keeping a copy of every program until the graded assignment is handed back.