Overview
In Exercise 12, you will write a utility class for working with a column of numerical values. This will give practice with constructors, methods, operator overloading and more. In the process, you will develop a keen understanding for the intuition and abstractions provided by a highly popular and valuable to understand library called NumPy
. We will explore NumPy later in the course!
In this exercise, you will build-up an abstraction, with many powerful capabilities, in the form of a class called Simpy
.
0. Pull the skeleton code
You will find the starter files needed by “pulling” from the course workspace repository. Before beginning, be sure to:
- Be sure you are in your course workspace. Open the file explorer and you should see your work for the course. If you do not, open your course workspace through File > Open Recent.
- Open the Source Control View by clicking the 3-node (circles) graph (connected by lines) icon in your sidebar or opening the command palatte and searching for Source Control.
- Click the Ellipses in the Source Control pane and select “Pull” from the drop-down menu. This will begin the pulling process from the course repository. It should silently succeed.
- Return to the File Explorer pane and open the
exercises
directory. You should see it now contains the directory namedex12
. If you expand those directories, you will see the starter files for this exercise. You should notice theex12
directory appear.
If the above did not work, try the following:
- Click the Ellipses in the Source Control pane and select “Pull, Push” from the drop-down menu. Then select “Pull from”. Then select “upstream” and the
main
option. This will begin the pulling process from the course repository. It should silently succeed. - Return to the File Explorer pane and open the
exercises
directory. You should see it now contains another directory namedex12
. If you expand that directory, you should see the starter files If you expand that directory, you will see the starter files:Simpy.py
andSimpyDemos.ipynb
.
1. Starter Files
Your work in this exercise will be completed across two files:
Simpy.py
- This is the Python module where yourSimpy
class is implemented.SimpyDemos.ipynb
- This is the Jupyter Notebook file that walks you through each of the methods ofSimpy
and provides sample uses. There are additionally a few check for understanding cells that will ask you to solve problems in terms of methods you previously implemented.
The descriptions of the functions you will need to implement, as well as example code that makes use of those functions once they are correctly implemented, can be found in the SimpyDemos.ipynb
file.
If your screen is large enough, you are encouraged to open these files side-by-side in VSCode by dragging the tab of one to the right side of VSCode so that it changes to a split pane view. Closing your file explorer can help give you additional horizontal space.
Be sure to save your work in Simpy.py
before reevaluating cells in SimpyDemos.ipynb
. Sometimes the Jupyter Notebook can reach a bad state and the only way to fix is to close your ipynb
tab and reopen a new one, thus restarting the kernel.
Corrections
If there are corrections or clarifications needed to the instructions in the ipynb
file, they will post in this section.
In the SimpyDemos.ipynb
file, we try to test your __add__
method by creating a new Simpy
object and storing it in a variable named a
and then printing the result of a + 1
. Since 1 is interpreted as an int
rather than a float
, isinstance(rhs, float)
would return False
. To avoid this causing any errors, make sure you first test whether rhs
is an instance of a Simpy
and then use an else
block to cover the case that rhs
is an instance of a float
OR you can edit the notebook cell to be a + 1.0
. Either will be fine, and will ultimately not impact the autograded score at all.
Autograding
Login to Gradescope and select the assignment named "EX12 - Simpy. You’ll see an area to upload a zip file. To produce a zip file for autograding, return back to Visual Studio Code.
If you do not see a Terminal at the bottom of your screen, open the Command Palette and search for “View: Toggle Integrated Terminal”.
To produce a zip file for ex12
, type the following command (all on a single line):
python -m tools.submission exercises/ex12
In the file explorer pane, look to find the zip file named “21.mm.dd-hh.mm-exercises-ex12.zip”. The “mm”, “dd”, and so on, are timestamps with the current month, day, hour, minute. If you right click on this file and select “Reveal in File Explorer” on Windows or “Reveal in Finder” on Mac, the zip file’s location on your computer will open. Upload this file to Gradescope to submit your work for this exercise.
Autograding will take a few moments to complete. For this exercise there will be 10 points manually graded to just verify that you ran the notebook cells. If there are issues reported, you are encouraged to try and resolve them and resubmit. If for any reason you aren’t receiving full credit and aren’t sure what to try next, come give us a visit in office hours!