By the time you have completed this lab, you should be able to
Work with your assigned pair programming partner on this lab. If you do not have one, consult the TA for your lab and/or your instructor for advice prior to starting.
You can find the video "Fun with Pair Programming" at this link. It takes less than 10 minutes to watch it.
Just as the in the video "Fun with Pair Programming", you and one other person will sit at a single terminal and write code.
From the video, you should be familiar with the roles of "driver" and "navigator", and the need for switching roles often. If not, then watch the video.
You'll be asked to evaluate your pair partner, and your pair partner will also evaluate you. These are the questions you'll be asked. You may find it helpful to consider those before you begin work—you certainly want your pair partner to say good things about you.
(Previous experience with pair-programming in courses suggests that 95% of students do end up giving their pair good evaluations—make sure you are part of the 95%!)
1. Did your partner read the lab assignment and preparatory materials before coming to the scheduled lab? [For example, did he/she watch the pair programming video before coming to lab]
2. Did your partner do their fair share of the work?
3. Did your partner cooperatively follow the pair programming model
(rotating roles of driver and navigator)?
4. Did your partner make contributions to the completion of the lab assignment?
5. Did your partner cooperate?
Your pair partners evaluation will be counted as part of your grade for the course.
So please do work with your pair in a constructive way!
Also: know that the vast majority of your grade in this course is still based on individual work, not pair work—so while you do need to try to have the best pair experience possible, in the unlikely event that your experience does not go well, the impact on your grade is limited.
The pair programming roles: driver (or driver) and navigator
This may be your first experience with "Pair Programming." You will learn more about it as the quarter progresses. There are two roles: driver and navigator.
The deadline for lab00 is Friday 10/01 at 5pm and ideally you completed it before that time. (The deadline for lab01 is also 10/01 at 5pm.)
But if you haven't yet completed it, do it now even if it is late. I will accept lab00 without penalty through Friday 10/01 at 5pm.
After that, you cannot earn any points for lab00, but you are still responsible for completing it before we will give you a non-zero grade on any other lab.
That means, either
For the rest of these instructions, we are going to assume you are working in Cooper or CSIL. If not, you'll need to adapt the instructions to your computing environment.
If you are working on a PC or Mac, you may need to consult the page below for help with getting cTurtle.py correctly loaded onto your system before starting this lab. If you are having trouble, you may ask for instructor if there are resources to help you with this.
turninprogram. You can use a file transfer program such as WinSCP on Windows, or on Mac CyberDuck or Fetch. Figuring that out is up to you—but you may use the General Forum on Gauchospace to share information with one another about how to accomplish this on Windows or mac.
On Gauchospace, there is a "forum" (i.e. a discussion board) where you can register that you are a pair working together on lab01. Please log on to http://gauchospace.ucsb.edu with your UCSBNetID—your username is your UMail address without the @umail.ucsb.edu part, and your password is the one you use for umail. Then, find the "Forum for lab01 pair partners", and follow the instructions there to make a post registering your pair.
This step is almost 10% of your grade for this lab (20 pts out of 220), so be sure you do it!
First, create a directory (folder) called lab01, inside your cs8 folder, which is in turn, inside your home directory.
There are two ways to do it:
If you've forgotten how, consult the instructions for lab00. If you still can't figure it out, you may ask a classmate, or the TA or instructor for help.
To bring up IDLE, type this command in the Terminal window, just like we did last week:
When you do, you should see the IDLE program come up. The window that appears should have the Python Command prompt (>>>) in it.
Next, in IDLE, select "File=>New Window" to open a new "untitled" window for Python code.
When it comes up, click and drag the window by its title bar over to the right of your Python Shell window.
Here's what that looks like:
|Selecting File=>New Window||The "untitled" window appearing||Dragging the windows so they are side-by-side|
Once you've opened that file, add a comment to the top of your file like this one (substituting your own name and the current date in the proper spot):
# lab01AgnesNitt.py by Agnes Nitt, for CS8 lab01, 08/12/2010 # some functions to draw pictures using Turtle Graphics
Then, save it under the name lab01YourName.py—for example:
Now proceed with Step 6.
Now, you should be ready to get started with Fred the Turtle.
First, to make sure that you have Turtle Graphics available, try this command at the Python shell prompt (>>>):
>>> import cTurtle
If what you get back is just another Python prompt (not a bunch of error messages) then you are good to go.
Next, in the right hand window (the one with the function definitions), put the following commands, after the initial comments:
import cTurtle fred = cTurtle.Turtle("turtle")
Next type in the function definition for drawing a square that we discussed in lecture. You'll put this in the window with the function definitions. If you've already got this function in your file, be sure you add a comment in front of it, as in the example below:
# function to draw a square # consumes: name of a turtle, and length of a side
# draws: a square, starting in the direction the turtle is facing,
# and drawing the top of the square first
def drawSquare(t, sideLength):
for i in range(4): t.forward(sideLength) t.right(90)
Once you've typed this in, use the Run => Run Module command to "compile" your Python code. In the Python Shell window, you should see something like this:
>>> ================================ RESTART ================================
import cTurtleline. These lines only work if cTurtle.py has been downloaded into the directory shown inside the quotation marks:
import sys; sys.path.append("c:/cs8");
import sys; sys.path.append("/Users/Shared/cs8");
Now, to test your function, try calling it with various values for sideLength:
>>> drawSquare(fred, 200) >>> drawSquare(fred, 50)
You can also try moving fred between the squares, picking up the pen first—for example this will move Fred over a bit before drawing the next square. The semicolons just allow us to put lots of function calls all on the same line.
>>> fred.right(90); fred.up(); fred.forward(200); fred.left(90); fred.down() >>> drawSquare(fred, 75)
You should see that you can draw squares of various sizes.
If that's true, then move on to Step 7.
Next, write your own functions to do each of the following. As you make the functions, test them.
(a) Draw a Triangle (any kind will do—could be equilateral, or could be something else.)
(b) Draw a Yield sign like this one. (Here, the sign should be an equilateral triangle)
(If you haven't switched roles yet (driver/navigator), in between steps b and c is a good time to do it.)
(c) Draw a House similar to this one
(Note: your house doesn't have to look exactly like this—i.e. the proportions of the width/height and the steepness of the roof can be different. As long as it "looks like a house", that's good enough for this lab.)
(d) Come up with your own drawing. Try to make it something that can be generalized—that is, have one or more parameters to the function that makes your drawing.
The parameter might be: the length, height, width, or the x and y location of where you "goto" before you start the drawing. You may like to think about whether you include a "penup" or "pendown" in your function to be sure the turtle actually draws something.
(Switch roles at least once during making your own drawing.)
Next, to help your TA test your work, you are going to make a driver function called go().
The driver function is one that will make several function calls to your functions to show that they work properly. You may want to move the turtle around the screen a bit to make room for all of your drawings. As you do, you can pick up the pen and then put it down again.
Here is an example of a driver function, and the resulting drawing. Your driver function does not have to be exactly like this one—in fact, I encourage you to experiment and change it up a bit. The only requirement is that you need to call each of your other functions at least once, and the drawings should not overlap each other.
You'll see that after the definition of the driver function there is this line, all by itself
That line is a function call to the driver function, and it is the last line in the file—that way, each time you choose Run => Run Module or hit F5, the functions are all defined, and then the go() function is automatically called. This way, if your TA loads your program and hits F5, the TA can immediately see if your program works properly.
Example driver function (and call to go() ):
# Make a driver function def go(): # back up Fred 200 pixels fred.up(); fred.backward(200); fred.down() # draw a square, and move over a bit drawSquare(fred, 50); fred.up(); fred.forward(75); fred.down() # draw a triangle, and move over a bit drawTriangle(fred, 60) fred.up(); fred.forward(75); fred.down() # draw a yield sign, and move over a bit drawYieldSign(fred, 50) fred.up(); fred.forward(100); fred.down() # draw a house sign, and move over a bit drawHouse(fred, 100) fred.up(); fred.forward(150); fred.down() # draw a hexagon, and move over a bit drawHexagonThing(fred, 40) fred.up(); fred.forward(110); fred.down() # draw a bunch of hexagons for i in range(40,70,10): drawHexagonThing(fred, i) go()
Sample output (yours may look different—in fact, I hope that it will!)
When you have a driver function you are almost ready for submission. Just a few minor checks first
Before you submit your assignment, check these things:
There are several ways to get the file
lab01YourName.py from your PC or Mac onto CSIL.
One of the easiest, though not the most efficient or direct is via email:
There are better ways though—ways that do not require you to visit Cooper or CSIL in person. The most straightforward way is this:
pscp(which comes with putty) and WinSCP are free secure file transfer programs
scpprogram can be used at the Terminal prompt, or you can use CyberDuck (free) or a commerical program such as Fetch.
To submit your assignment, you need to bring up a terminal window on CSIL.
Next, we use the cd command that we practiced earlier:
-bash-3.00$ cd -bash-3.00$ pwd /cs/student/yourusername -bash-3.00$ cd cs8 -bash-3.00$ pwd /cs/student/yourusername/cs8 -bash-3.00$
When you are in inside your cs8 directory, you are ready for the turnin step.
Type the following at the prompt:
turnin lab01@cs8 lab01
You should be asked if you want to turn in this program. Respond "yes", and then you should get a message indicating that your efforts were successful!
Before you finish up if you didn't submit yet, you'll copy your work to each of the other student's accounts on your team.
Note: DO NOT share passwords with each other.
That is a violation of your account agreement, and can result in suspension of your computing privileges at UCSB.
Here's what you can do instead:
OR use the scp solution below, which is even better.
That way, if your pair partner gets hit by a bus, you can continue working without him/her—you aren't 'out of luck'.
A better solution is to use scp to copy the work from person1's account into person2's account with the scp command—here's how:
It is only necessary for one of you to submit the work via turnin, as long as both names are in each file.
But, if you are the person whose account is not the one from which the turnin step is done, be SURE that your name appears! You need to work carefully with your pair partner to avoid misunderstandings and problems.
Some final thoughts on this step:
Copyright 2010, Phillip T. Conrad, CS Dept, UC Santa Barbara. Permission to copy for non-commercial, non-profit, educational purposes granted, provided appropriate credit is given; all other rights reserved.