← HW 0 overview

Programming Task

CMSC 141 • HW 0, part 6 of 6

In this last section you will edit a small program, run it, push your change to GitHub, and submit on Gradescope. This is the same routine you will use for every assignment, so it is worth doing slowly and carefully once.

Set up the assignment's uv project

Move into your cloned repository directory:

$ cd ~/cmsc141/hw0-[lastname]

The file you will edit, hw0.py, is already in this directory. It may be a little longer than the snippets below; that is fine. You only need the one line marked with a comment.

Each assignment is its own uv project. Install the tools it needs with:

$ uv sync

This can be slow the first time. It installs the libraries the assignment depends on.

Open the file

Open the repository directory in your editor:

$ codium .

Or launch VSCodium and use File → Open Folder to open your hw0-[lastname] folder. Then click hw0.py to open it.

Edit the code

Find the line marked with the comment # Replace None with 2 + 2 in the next line and do exactly that: change None to 2 + 2. Save the file with Ctrl-s (Command-s on macOS).

Run the program

You can use VSCodium's built-in terminal (Terminal → New Terminal) or the terminal where you ran uv sync. Confirm you are in your hw0-[lastname] directory with pwd, then run:

$ uv run python3 hw0.py

The file runs every exercise's test cases, so you will see a wall of output. You don't need to read all of it right now. Before you have written any code, the unedited file prints this:

2 + 2 is None
Testing add_one_and_multiply
expecting 12
None
Testing to_fahrenheit
expecting 212.0
None
Testing calculate_bill_per_person
expecting 30.0
None
Testing is_even
expecting True
None
Testing convert_to_seconds
expecting 3661
None
Testing find_day_of_the_week
expecting 6
None
Testing is_leap_year
expecting True
None
Testing min_no_conditionals
expecting 3
None
Testing is_whole_number
expecting True
None

The first line is the one that confirms your setup. Once you finish Exercise 0 and save, that line should read 2 + 2 is 4 instead of 2 + 2 is None. If it still says 2 + 2 is None after you edited the file, you probably did not save before running. If you see an error like can't open file 'hw0.py', you are in the wrong directory.

Everything below that first line is a test harness: a small chunk of code whose only job is to call each of your functions with sample inputs and print the results, so you can check your work. For each exercise it prints what the test expects (for example expecting 12) and then, on the next line, what your function actually returned. Right now every function returns None because you haven't written them yet, so the value never matches what's expected.

Your job is to edit the code so your output looks like this, with each returned value matching the line above it:

2 + 2 is 4
Testing add_one_and_multiply
expecting 12
12
Testing to_fahrenheit
expecting 212.0
212.0
Testing calculate_bill_per_person
expecting 30.0
30.0
Testing is_even
expecting True
True
Testing convert_to_seconds
expecting 3661
3661
Testing find_day_of_the_week
expecting 6
6
Testing is_leap_year
expecting True
True
Testing min_no_conditionals
expecting 3
3
Testing is_whole_number
expecting True
True

When the line under each expecting matches the expected value, that exercise is working. Complete all of them before you submit.

Sync your change

Stage, commit, and push your work:

$ git add hw0.py
$ git commit -m"Finish HW 0 deliverable"
$ git push

You can use git add -u . instead of naming the file. Then confirm a clean, synced tree:

$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

Submit on Gradescope

Once your change is pushed, submit through Gradescope under Homework 0. Gradescope pulls your files straight from GitHub, so your work has to be pushed first.

On your first submission you will connect Gradescope to GitHub: click Connect to GitHub and authorize it. Then choose your repository, select the main branch, and click Upload. An autograder runs and reports a score; wait for it to finish.

If the score comes back as 0, the usual cause is forgetting to save or to push your change. Fix that and resubmit. You can submit as many times as you like.