Lab 1: Getting Started

19 January 2024

Today’s lab

If you have trouble, raise your hand – we’re here to help!

The purpose of this initial lab is to acquaint you with

  • your new CS Department Linux account,
  • using the code.pyret.org (CPO) programming environment and
  • the procedure for submitting your work electronically.

Contents

Your CS account

Each student taking a CS class at Vassar has a user account on the department computers. You’ll use this account when you’re completing labs.

Task: Log in to your account. Your username is the same as your Vassar username. The instructor will tell you the initial password.

Everyone has the same initial password, so that’s not very secure. We need to change it! Any accounts still using the default password will be locked before next week. Don’t let that happen to you!

Task: Change your password.

  • Click on the menu in the upper left corner → AllAbout Me. In the window that opens, click Change Password…

  • Enter the default password and click the Authenticate button to verify. Then enter your new password in each of the two password fields and click Change password.

To make sure it worked correctly, let’s log out and log in again:

Task: Close the Change password and About me windows. Click the gear icon next to the date in the upper right corner and select Log Out… and click Log Out in the window that opens. Then log in with your new password!

Signing in to CPO

Next we want to connect CPO – the environment for programming in Pyret – to your Google Drive account so you can save your work and access it from anywhere.

Task: Use the menu in the upper left to open a web browser (e.g., Firefox) and enter code.pyret.org in the address bar.

Task: Click Sign in and follow the prompts to link CPO with your Vassar Google account.

The Pyret editor

Getting used to the Pyret editor can be a bit tricky. Let us help you navigate your way through it!

Task: Click Open Editor.

You’ll be presented with a screen that’s divided into two panes:

  • The definitions pane (left) is where you’ll provide Pyret with the program you want it to run. The program could consist of definitions (assignment of variables to expressions or functions), expressions, or both.
  • The interactions pane (right) is where the results of running your program are displayed and where you can experiment.

Before we continue, you might want to customize CPO a bit:

Task: Click on the View menu and adjust the font size and colors CPO will use. You can make yourself comfortable or stick with the defaults.

Now you’re ready to begin programming!

Interacting with Pyret

Task: Try evaluating the following expressions in the interactions pane.

  1. In the interactions pane, type:

    ››› 1
    

    and press enter. This gets evaluated and – unsurprisingly – the result is also the number 1!

  2. Let’s be slightly more daring! Try the following:

    ››› 1 + 2 + 3
    

    Hopefully the answer is 6!

  3. Notice what happens if you instead try this:

    ››› 1 + 2 - 3
    

    Pyret doesn’t know order of operations! When it’s just +, it doesn’t need to, but when you mix operators, you need to add parentheses to tell Pyret what to do first.

Defining a program

For this lab, you’ll create a program just by copy-and-pasting code into CPO’s definitions pane. In future labs and assignments, you’ll type in your own code, but for the purposes of this lab, we thought we’d give you a head start!

Task: Copy-and-paste the following lines of code into CPO’s definitions pane (on the left):

# CMPU 101 Lab 1
# Evaluating different types of data expressions


#
# Exercise 1: Numbers
#

# The following expression adds three numbers:
(40 + 1) + 1


#
# Exercise 2: Strings
#

# The following expression appends two text strings:
string-append("Computer ", "Science")


#
# Exercise 3: Images
#

# The following expression draws a solid red circle with a radius
# of 10 pixels:
circle(10, "solid", "red")

# And the following expression gives a name to a friendly rectangle:
fred = rectangle(100, 20, "solid", "black")
# Now the name, fred, evaluates to the image:
fred

# The following expression overlays a circle on fred, producing a new
# image:
overlay(
  circle(20, "solid", "red"),
  fred)

The lines that start with number signs (#) are not evaluated by the computer – they’re comments for human readers.

Don’t worry if you don’t understand everything you just pasted into CPO, but feel free to ask questions!

Task: Run the program by clicking the Run button at the top (or use the shortcut Ctrl-enter).

Experimenting

If there is a syntax error somewhere in your code, Pyret will generate a syntax error.

Task: To see what a syntax error looks like, remove the right parenthesis from the end of one of the expressions and click Run again.

Read Pyret’s explanation of the error. In this case, you already knew what was wrong, but when you don’t, carefully reading the error messages will help.

Task: Add the parenthesis back and check that the code now runs without an error.

The starter program includes example expressions working with numbers, text strings, and images. Next we’ll try writing some new expressions for each data type.

See if you get the results you expect. Be daring! In the worst case, you can always copy-and-paste the original again.

Task: Under Exercise 1, add expressions that subtract, multiply, and divide numbers. Use * as the multiplication sign and / as the division sign.

Task: Under Exercise 2, add an expression that appends three or more text strings.

Task: Under Exercise 3, try making an image of your choice using at least three different shapes and colors. You may want to give names to parts of your image.

Saving and submitting your work

When your modified program runs successfully, you’re ready to finish the lab by having your work checked and uploading a copy to Gradescope.

Task: Raise your hand to show it to the professor or one of the student coaches, who will record that it was completed.

Task: Save your program by clicking FileSave a copy and giving it a name. Note: CPO sometimes auto-saves. Don’t rely on this! Make sure you frequently save your work! You can click FileSave or use the keyboard shortcut Ctrl-s.

Now if you click on FileMy Programs, you’ll be shown a list of all your programs, including the one you just saved. These are stored in Google Drive. When you look at your Google Drive account, you’ll see your Pyret files in a folder called code.pyret.org.

Task: Download a copy of your lab to the computer: FileDownload.

Now we’ll upload it to Gradescope.

Task: Log in to Gradescope using your Vassar account and click on the course name and then on Lab 1.

Click on the prompt Click to browse, select your lab file, and click Upload.

You can submit new versions of your work on Gradescope up until the deadline. For labs, that’s the following Friday.

If you have more time left in lab, feel free to start the assigned reading, following along and experimenting in Pyret.

Task: Log out by click the gear icon next to the date in the top panel and selecting Log Out… and follow any remaining prompts.

Always remember to log out when you are done using the system, to ensure that no one else uses your account. (But don’t shut the computer off!)

That’s it! 🎉