
The purpose of this lab time is to give you an introduction to the basic tools we will be using this semester. These tools include a terminal, a text editor, and the Python interpreter.
You will also write your very first Python program then turn it in to practice submitting your weekly projects.
Labs. During each week's lab, you will get hands-on practice with concepts from lecture. Labs are also the starting point for the weekly project.
Projects. In the projects, you will get deeper experience working with concepts from lecture by writing Python code and running it to create outputs that you design, such as images.
Project report. You create a Google Doc with images from your project, along with a description of how you created them and what you learned. Labs and projects are tightly coupled.
Submission. Each week, you will see the current project posted on Google Classroom, along with the due date. To turn in your project, click on the post and attach:
The goal of today's lab is to give you to practice completing each of these steps.
If you have not already done so, complete Lab 0 to get your computer ready for CS151.
Let's spend a few minutes talking about the Terminal as a class.
Open up the VS Code text editor.
Open up the Terminal built into VS Code by typing Control+` ( ` is the same key as ~ near the Esc key). Alternatively, you can click the Terminal menu and select New Terminal (Windows: top of the VS Code window. Mac: In the menubar at the top of your screen).

The Terminal a text-based, keyboard-only interface of using your computer. This is an alternative way to use your computer compared to the graphical interface that you're used to where you click on things like icons, folders, buttons, etc. Voice assistants like Siri and Google Assistant are alternative interfaces to your phone. Anything you can do in the Finder, you can do in Terminal.
Why learn Terminal?
Just like the Finder (Mac) or Windows Explorer (Windows), with Terminal you are always "in" a particular folder (directory) of your computer. The current directory is called your working directory. A terminal will usually start in the your home directory. On my Mac, this is:
/Users/hewolfe
If you are on Windows, it will look something like:
C:\Users\hewolfe
As you can see above, directories are separated by a slash. On Macs this is the forward slash /, on Windows this is a backward slash \. They have the same meaning (but you cannot substitute one for the other if you are on a Mac!).
Windows users: The following instructions are written with the forward slash convention, but on Windows forward and backward slashes are interchangeable, so you can still follow along exactly as things are written.
My home directory /Users/hewolfe is an example of a path, which is a complete description of where a directory or file on my computer. Paths usually are case-sensitive, so be sure to use proper capitalization (i.e. /Users/hewolfe has a different meaning than /USERS/hewolfe). You will use paths, and filenames to change directories, list the contents of directories, and run Python programs.
Here are some important commands that you type into the Terminal to know for this class. You hit the Return key to actually run the command.
These three commands are super helpful and important for navigating the Terminal:
pwd: Stands for "print working directory". It tells you where you currently are on your computer. For example, when you open the Terminal, usually you are in your home folder. Typing pwd then Enter will tell you this: /Users/hewolfels: Stands for "list" the files/folders in the current directory. See all the folders and files in the current folder that you are "in".cd <type in a directory here>: Stands for "change directory". You type the command, followed by a space, followed by the directory or path you want to go to. Want to just move up one folder from where you are? cd ... Move up 2 folders? cd ../... etc. Here are some examples:| Command | Meaning |
|---|---|
| cd ~ | Set the current directory to your home directory. (The ~ character is shorthand for your home directory.) |
| cd .. | Move up to the parent directory of the current working directory (one folder "up" fro where you are) |
| cd ../../ | Move up to the parent of the parent of the current working directory. |
| cd blah | Move into the sub-directory blah |
| cd /Users/hewolfe/Desktop | Move to the Desktop directory give by the absolute path (starts with /). |
Use the "lifeline" commands all the time: As you are getting comfortable using the Terminal, always enter the pwd and ls commands to "see" where you are on your computer.
Hitting return anywhere: You don't have to be at the end of the line to press return. If you go back and edit something in a terminal command, you can press return and execute the whole line no matter where the cursor is located.
Drag folder icon into Terminal (Mac): The best tip. Often you have your project/lab folder in Finder and want to run the code in it. You need Terminal to "look at" the same folder to do this. Since opening usually Terminal starts you in your home folder (e.g. /Users/hewolfe for me), it can be a chore to cd your way to the project folder. There is an easier way. Type cd, space, then drag the blue folder icon at the top of Finder (next to your project folder name; see screenshot below) into the Terminal window. The correct path will magically appear and you can hit Return to move Terminal there!
![]()
Drag folder into Terminal (Windows): The best tip. Often you have your project/lab folder in Finder and want to run the code in it. You need Terminal to "look at" the same folder to do this. Since opening usually Terminal starts you in your home folder (e.g. C:\Users\hewolfe for me), it can be a chore to cd your way to the project folder. There is an easier way. Type cd, space, drag the folder into the terminal from Windows Explorer. The correct path will magically appear and you can hit Return to move Terminal there!
Tab completion: Big, big time saver. When you start typing the name of a file or folder, press the Tab key. It will finish the typing for you! After it finishes, you can keep typing a little more, then hit Tab again to have it complete more. Example: Typing cd /Us then Tab results in: cd /Users/. If I then type "o" then Tab, it gives me cd /Users/hewolfe/.
bye and bay and type "a" so your command looks like cd ba, it will autocomplete to bay.Project and Lab, typing cd P then Tab will give you cd Project/.Now it is your turn! Do the following exercises to practice working with the terminal.
Mac users: In Finder, go to your Desktop and create a folder called Project01. Open it. Use the drag folder icon trick to navigate your Terminal to the Project01 folder. You know you got this working if the pwd command gives you /Users/<your user name>/Desktop/Project01.
Windows users: In Windows Explorer, go to your Desktop and create a folder called Project01. Use the drag folder trick to navigate your Terminal to the Project01 folder. You know you got this working if the pwd command gives you C:\Users\<your user name>\Desktop\Project01.
More practice: make a Lab 1 folder in Finder/Windows Explorer or Terminal (up to you how you do it). Call it Lab01. Change directories to it so it is the current folder in the Terminal.
You know you got this working if you typing and entering the pwd command gives you /Users/<your user name>/Desktop/Lab01 (Windows users: C:\Users\<your user name>\Desktop\Lab01).
Python is a simple yet powerful language for making computers do stuff. Many people have written modules for Python that do some sophisticated things. One of those modules is called turtle. We will use turtle extensively all semester!
Think of turtle as a virtual turtle that drags along a pen underneath it. As you command the turtle to move, the pen leaves ink on the virtual sheet of paper.
We can make the turtle move forward, backward, turn left, turn right, and pick up or put down the pen using the following commands.
forward(x) - move forward x pixelsbackward(x) - move backward x pixelsleft(a) - turn left a degreesright(a) - turn right a degreesup() - pick up the pen (don't draw when the turtle moves)down() - put the pen down (draw when the turtle moves)You can find out about more turtle commands on the Python documentation site.
Text editors are the workhorse programs for writing code. Unlike Google Docs and Microsoft Word, we don't want fancy fonts or formatting. In lecture and lab, we will use the Microsoft Visual Studio Code editor (VS Code for short). Let's use VS code to write our first Python program.
Do not write code in Microsoft Word or Google Docs!
Now let's write your first Python program! Your goal is to use turtle to draw a hexagon:
from turtle import *exitonclick()hexagon.py and place it in your Lab01 directory on your Desktop. The .py is important — it tells your computer that this will be a Python code file.right and forward turtle functions commands. Place only one command per line, in between the import and exitonclick commands.python3 hexagon.pypython3 blah.py type instead py blah.py.Congratulations, you just ran your first Python program! (Python Humor)
Didn't work? Here are some tips:
hexagon.py. Remember that you changed the working directory to Lab01 on your Desktop in Task L2. So, one thing you need to do when working on a project is to ensure that your Terminal is in the right directory. Think of it as making sure VS Code and Terminal agree where they are "looking" to see your code. You can always use ls to see the contents of the current directory and/or pwd to check what the current directory is.from turtle import * forward(100) right(90) forward(50) exitonclick()
exitonclick the last command?In hexagon.py, temporarily remove the last line exitonclick(). What happens?
After you see what it does (by removing it), add it back in.
For each project, you will write a brief report in Google Docs and submit it on Google Classroom.
Each report consists of:
All this will become second nature in a few weeks and is summarized in each project rubric on Google Classroom.
Let's turn in a "mock" lab report with a screenshot of your hexagon to help you get the hang of it. This is only practice, going forward you will not need to turn in labs, only projects.
Take a screenshot of your hexagon.
You can easily take a screenshot of your turtle creations to include in your reports by pressing Shift-Command-4. When you press those keys on your keyboard, a crosshair will pop up. Click and drag to draw a box around your hexagon. When you let go, a screenshot of the region that you selected gets saved to your Desktop.
Follow the "Mouse and keyboard" directions to use the Windows Snip Tool to take screenshots. You want to use the Rectangular or Window option. With the Rectangular option, you click and drag a box (while holding down the click) around your hexagon when the screen dims. Let go when you are satisfied. Once you see your screenshot preview in Snip Tool, save it to your Desktop (File -> Save As).
Let's upload your code in the proper format to Google Classroom and turn in your lab. You should follow the same steps when turning in your projects.
To make this as close to a normal project submission as possible, move your lab folder inside your project folder. For example, if you have Lab01 and Project01 folders both on your Desktop, drag the Lab01 folder inside Project01.
Create a zip file of your project:
macOS: Right-click the project folder (e.g. Project01) and click Compress "Project01".

Windows: Right-click the project folder (e.g. Project01) and click "Compressed (zipped) folder" in the "Send to" menu.

Important: Name your zip file your Colby username. For example, I would name mine hewolfe.zip.
In the Lab 1 assignment on Google Classroom, click "+ Add or create" > click "File" > click the "UPLOAD" tab > drag in your .ZIP folder. It should upload and bring you back to the Lab 01 assignment page. It may ask you if you turn in your Google Doc lab report, .ZIP file, and rubric. You can click "Turn in". If you don't want to submit yet, click "Cancel", it will bring you back to the assignment page again. You can always click the "Turn in" button on the right whenever you are ready.
Click "Turn in" to officially submit your lab!
Once you are done with each of the lab tasks, you may start on the project.
© 2021 Hannen Wolfe and Oliver Layton