How to complete assignments
Assignments are contained in the assignments directory. There is one directory per assignment. Each assignment has specific instructions in the README.md
file in the assignment directory.
For most assignments, you will be editing the file named main.py
in the assignment directory. The instructions will explicitly note if other files need to be edited.
Your code is automatically saved & uploaded when you edit it. You don't need to do anything to submit. The most recent version of your code (from before the problem set deadline) will be graded.
Click on main.py
in an assignment directory to open it. You can test your code manually by clicking the Run
button at the top left of the text editor.
![](/brandeis-cosi-10a/class-exercises/raw/main/.images/code_play.png)
Testing your code
You can always test your code manually by clicking on the Run
button at the top right of the editor when you have a Python file open. This will run your program, and show its output in the terminal at the bottom.
Most assignments also come with automated tests. To run them, click on the Testing
icon on the left side of VSCode, then click the "play" button on the test or tests you want to run.
![](/brandeis-cosi-10a/class-exercises/raw/main/.images/running_tests.png)
If you submit with any automated tests failing, you will not receive full credit for the assignment. Part of the challenge of the assignments is to make your code generate the output the tests are expecting. If your tests are failing - even if the failure seems trivial to you - you should try to fix them before submiting. Get help from the course staff if you feel stuck!
The early assignments in this class use input/output tests. These send input to your program, and ensure that your program produces the expected output. The actual output must match the expected output (almost) exactly - only blank lines are ignored.
When you run input/output tests, if they fail, a side-by-side difference of the expected and actual output are automatically shown. If you have many failures, you may want to run a single test at a time.
![](/brandeis-cosi-10a/class-exercises/raw/main/.images/iotest_diff.png)
If you explore the "testcases" directories under each assignment, you can see each test case. They include:
input.txt
: The input sent to your programexpected.txt
: The expected output- (after you run at least once)
actual.txt
: The actual output your program produced the last time it ran
![](/brandeis-cosi-10a/class-exercises/raw/main/.images/iotest_find_files.png)
Debugging your code
Actually READ your error messages!
While certain types of mistakes will produce messages that seem completely unrelated to the actual error, most of the time the error message tells you what is wrong, and points out the offending line.
Adding print statements to your code is an effective (if inelegant) way to understand why your code isn't behaving the way you expect it to.
Try:
- Printing hardcoded messages at certain points in the program, to see when (or if) your program reaches those points.
- Printing out the value of variables just before a conditional, to see why the conditional isn't working the way you expect
- Printing out the value of variables just before a crash, to see why your program is dying
Debuggers are tools that allow you to advance through a program, step by step, and examine the state of the program at each step. They are very powerful tools.
VSCode has a Python debugger built in!
The typical flow is:
- Set a "breakpoint" - a breakpoint is a place in the program where the debugger will pause when it is reached.
- Launch the debugger
- Once code execution reaches the breakpoint, examine the state of the program, or continue stepping through line by line.
![](/brandeis-cosi-10a/class-exercises/raw/main/.images/debugger_launch.png)
![](/brandeis-cosi-10a/class-exercises/raw/main/.images/debugger_tour.png)