Lab 1: Getting Started

2 September 2022

The instructor will provide instructions to log into your Linux accounts on the classroom workstations and set your passwords.

The purpose of this initial lab is to acquaint you with

  • using the code.pyret.org (CPO) programming environment and
  • the procedure for submitting your work electronically.

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

  1. Use our CS account to log in to one of the Linux workstations in the classroom.

  2. To open a web browser, click on the menu in the upper left corner, select Internet, and open Firefox (or the browser of your choice).

  3. Enter code.pyret.org in the address bar.

  4. Click Sign in and follow the prompts to link it with your vassar.edu Google account.

  5. Click Open Editor.

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

When CPO loads, 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: Click on the View menu and you can adjust the font size or change the colors CPO will use. You can make yourself comfortable or stick with the defaults.

Now you’re ready to begin programming!

  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.

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

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

Okay, now 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 numbers:
(40 + 1) + 1

# TASK: Try adding expressions that subtract, multiply, and divide numbers.


#
# Exercise 2: Strings
#

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

# TASK: Try adding an expression that appends three or more text strings.


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

# TASK: 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.

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

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

  2. If there’s a syntax error somewhere in your code, Pyret will generate a syntax error.

    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.

  3. Experiment! Read the comments describing the expressions you copied and try writing new expressions to complete each of the tasks.

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

  4. When your modified program successfully runs, raise your hand to show it to the professor or one of the student coaches and follow the submit procedure below.

  1. Save your program by clicking FileSave a copy and giving it a name.

    Note: CPO sometimes auto-saves. Do not rely on this! Make sure you frequently save your work! You can click FileSave or use the keyboard shortcut Ctrl-s.

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

  1. To submit your work, you first need to download a copy to the computer. Click FileDownload.

  2. Now we’ll upload it to Gradescope. In your browser, go to gradescope.com and log in. You should have received an email inviting you to sign up for Gradescope. If you didn’t, check your junk mail folder, and then let the professor know.

  3. You’ll see a list of courses you’re enrolled it. Click on the ID of your section.

  4. Now you’ll see a list of assignments for the course. For now the only one is "Lab 1". Click on it.

  5. Click on the prompt Click to browse and select your lab file.

  6. Click Upload.

You can submit new versions of your work on Gradescope up until the deadline.

  1. Log out by clicking 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! 🎉

This lab includes material adapted from Kathi Fisler and colleagues at Brown University.