Lab 1: Python Environment

        An Introduction

Weekly CS151 workflow

Labs. During each week's lab, you will get hands-on practice with concepts from the 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 the previous webpage, along with the due date. To turn in your project, go to your the Google Drive folder I shared with you earlier and drag and drop the following files to the project folder:

The goal of today's lab is to give you to practice completing each of these steps.

Introduction to Python turtle

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.

You can find out about more turtle commands on the Python documentation site.

Write your first Python program!

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:

  1. Open VS Code.
  2. Create a new code file from within VS Code (Cmd+N).
    Windows users: Always substitute Cmd for the Control key.
  3. Import the turtle module. On the first line of your code file, write the command:
    from turtle import *
    This will make all of the turtle commands available to you (i.e. allow you to instruct the turtle to draw for you.)
  4. On the last line, write:
    exitonclick()
    This will keep the turtle window open until you click on the turtle window that pops up.
  5. Save your file (Cmd+S). Name it 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.
  6. Have the turtle draw a hexagon using the right and forward turtle functions commands. Place only one command per line, in between the import and exitonclick commands.
  7. Instruct Python to execute (run) the program. To run your program click on the green play button at the top left side of your screen.
  8. If something does not work out, before moving on, change your code, save your file (Cmd+S) and run it again. Update and run your code until your turtle draws a hexagon.

Congratulations, you just ran your first Python program!

written project reports

For each project, you will write a brief report in Google Docs and submit it through your Google Drive folder that I shared with you earlier.

Each report consists of:

  1. A useful title, like "Otto's CS151 Lab 0: My First Python Program" so that the page content is clear from the title.
  2. Abstract: A one paragraph summary of the project.
  3. Results: Images showing what you created, alongside a description of what each image is and how you designed/created it with code.
  4. Reflection: A brief description (1-3 sentences) of what you learned.
  5. Sources: A list of people you worked with, including TAs, and professors.

All this will become second nature in a few weeks and is summarized in each project rubric

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 turtle creation

Take a screenshot of your hexagon.

Mac users

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.

Windows users

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).

Create a Lab 1 report

  1. Log onto Google drive, then navigate to the directory I shared with you earlier.
  2. Right-click inside the project folder and select “Google Docs” from the menu.
  3. This should open a new Google Doc. Give your report a meaningful title like "CS151 Lab 1: My First Python Program".
  4. In all of your project reports, you will need to include pictures of the images you created with your program. Drag in your screenshot of your hexagon from your desktop into the Google Doc. Resize/crop/format the image as necessary in your report.
  5. Always create a caption under your images describing what it is and how it was made. Underneath your hexagon image, write "I created a hexagon shape with Python using the turtle forward and right commands!"
  6. Add sections that should be in every CS151 report: Abstract, Results, Reflection, and Sources. They should be blank — do not write anything in them today.

Submitting a project

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.

Make sure your project directory includes the following files:

  1. Your lab folder including your  (.py)  code files and any produced images.
  2. Your project code (.py) files and any produced images.
  3. Your report as a Google Docs document containing the section listed in the rubric.
  4. An unmodified project rubric.