Lab 1, CSC202, Fall 2025
1 Getting a Development Environment set up
As the syllabus mentions, one way to get going with a development environment is to use GitHub Codespaces.
Another way to do this–the recommended way, if you’re a CSC major–is to set up a development environment on your own machine.
The following instructions are for setting up a development environment on your own machine. I’m grateful to Brian Jones, Stephen Beard, and others for this text, these links and their content.
2 Shell
Make sure you have a running shell that you can use to interact with various command-line tools. Here’s a guide to follow:
3 Git
Next: here’s a nice intro to git.
Read sections 0, 1, 2, and 3, and follow along with the instructions. Along the way, go ahead and sign up for a GitHub account, if you don’t already have one. Also, if you have a GitHub account but the account name is something like BROxxGAMERZxxBOIIIII and you don’t really want to share that with the rest of your professional contacts, creating a new account is fine for you too!
4 Generating an SSH key
In order to interact with GitHub, you’ll need to prove that you are who you say you are. The best way to do this is to generate an SSH key on your machine, and then share the public piece of this keypair with GitHub.
Here are instructions for doing this, for Windows and also for Mac/Linux:
In Windows:
https://www.purdue.edu/science/scienceit/ssh-keys-windows.html
Via command line (Linux, Mac, Windows WSL) (Note that you don’t need to setup the agent: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent Links to an external site.
After you’ve generated a key pair, share your public key with GitHub. BTW, if you are curious how it’s possible how sharing the public part of the key allows authentication, I’d be happy to tell you; it’s pretty amazing.
5 Python 3
Next, let’s check and see whether you have Python 3.13 installed. Open your terminal and try running
ENG-CLEMENTS-1:/tmp clements> python3 --version |
Python 3.13.2 |
ENG-CLEMENTS-1:/tmp clements> |
Does it look like this? If so: great!
If not: try python and py, it’s possible that the executable has another name.
Still no luck? Visit https://www.python.org/downloads/ to get the most recent version.
6 PyLance
In order to check our code for errors before runnnig it, we’ll be using Microsoft’s PyLance tool, which unsurprisingly has very good VS Code integration. You can find the tool in the extensions marketplace within VS Code, or get instructions by visiting https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance.
After installing the tool, go to its settings, and update the "Python: Analysis > Type Checking Mode" to be "strict".
7 Accepting the lab invitation, cloning the repo
Click on the invitation link to create your own private repository for this assignment.
- Clone your fresh new repo. It should contain a file named "lab1.py". Here’s how:
Copy the SSH link from github (not the https one).
using the terminal, change to an appropriate directory and run ‘git clone <paste link>‘. What’s an appropriate directory? Could be your main user directory, or perhaps a subdirectory you created for this course.
Edit this file to add a comment to Section 1, part 1, containing the word "persnickety".
Add, commit, and push your change.
Log into github using their web interface by visiting https://github.com/calpoly-csc202-2258/; make sure you can see your Lab 1 repo, and the word "persnickety." When you’re done with this, show an instructor; failing to correctly push can really mess up your grades in this course.
8 The rest of the lab
The rest of this lab contains many sections and many numbered parts of each section. You’ll see that the "lab1.py" template comes with lines indicating each of these sections and parts. You should put your answers to each part in the corresponding place in the code.
You should push your work to github after each part is done.
Note that several parts of this lab will ask you to create pieces of Python code that are incomplete, lacking data definitions or functions. That’s fine, we don’t expect the code to run. Don’t worry, that will be coming soon enough.
9 Data Definitions
Before proceeding with this lab, you should read about simple data definitions.
Each of the following programs requires a data definition. In many cases, it may be just a single TypeAlias line. In other cases, the data definition may require creation of a new class, or more than one class. In this case, be sure to create the class(es) using a @dataclass declaration, as discussed in class.
Provide two examples for each data definition.
A program that converts celsius to fahrenheit temperatures must accept a celsius temperature as input, and return a fahrenheit temperature as a result. Write a data definition for each of these two kinds of values.
A store might maintain a database that includes prices for various items. Write a data definition for a price (just the price), in cents.
Following on the prior item, write a data definition for a price record; it should include both the item’s name and its price.
A web browser might maintain information about open tabs. Develop a data definition for an open tab, that includes the URL being visited and the most recent date on which it was loaded. (Yes, this data definition may require sub-data-definitions).
10 Purpose Statements, Headers
For each of the following functions, provide a a purpose statement, and a header including input and output types. You do not need to provide the data definitions; you may assume that this has already been done. Many of these problems are underspecified; make reasionable assumptions.
A function that accepts a price and adds sales tax,
a function that finds the price for a named item in a store’s price database,
a function that computes the median income using a given geographic region and given database, and
a function that accepts a given geographic region and database and determines which cities overlap with that region.
11 Test Cases
For each of the following, write a purpose statement, a header (including types), and a set of test cases. Each test case should take the form of a method whose name begins with test, containing a sequence of calls to self.assertEqual.
None of these require a separate data definition.
You are not required to define the functions themselves! You should use the body "pass" for each function, to avoid making the indentation engine irritated.
A function that accepts three distinct numbers and returns the second largest,
a function that accepts a string and returns true if it has no capital letters,
a function that accepts the names of two states and returns the "northernmost" one; that is, the one that contains the point closest to the north pole.
12 Whole Functions
Follow the design recipe (data definitions if necessary, purpose statement, header with tests, test cases, fill in body) to design the following functions.
Place all of your tests for this section in a single TestCase class, so that you can run them.
For test cases on inexact (floating-point) numbers, you will want to use the assertAlmostEqual form. There are a number of different ways to use this form, but the one that probably makes the most sense here is the form that specifies a fixed number of decimal places after the point. So, for instance, this test should pass:
self.assertAlmostEqual(3.0004,1.5001242873 * 2,3) |
|
Develop the f2m function, that accepts a length represented as a number of feet and returns the corresponding length in meters.
Develop a data definition for a Musical Note, which includes a pitch represented as a frequency in Hz, and a duration represented as a length in seconds.
Develop the up_one_octave function, that accepts a note and returns a new note that is higher by one octave. In other words, its frequency is doubled.
(OPTIONAL) Develop the frequency_diff, that accepts two notes and computes the number of half-steps between them by dividing the logarithm of the ratio of the notes by the logarithm of the twelfth root of 2.
13 Lab Submission Servlet
Oh hey, how about another link to the lab submission servlet?