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:
Creating SSH Keys In Windows GUI: https://www.purdue.edu/science/scienceit/ssh-keys-windows.html Links to an external site. 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, then visit https://www.python.org/downloads/ to get the most recent version.
Click on the invitation link to create your own private repository for this assignment.
- Check out your fresh new repo. It should contain a file named "lab1.py". But how?
Copy the SSH link from github (not the https one).
git clone <paste link>
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; 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.
6 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. Your code will be sliced and diced programmatically, so if you put your work in the wrong part of the file, or delete or alter the existing headers, you might not get credit for your work, and that would make us *both* sad.
You should push your work to github after each part is done.
7 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. In this case, be sure to create the class 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).
8 Signature, 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 reasonable 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.
9 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.
In order to allow your code to type-check and run, you should add a near-trivial body to each function that simply returns something of the correct type. Note that I don’t expect the test cases to pass, or the function bodies to contain anything sensible; the point is to write correct test cases.
If you want to see your code run correctly, then, you should probably comment out these test cases after writing them.
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.
10 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.assertEqual(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.