CS1302 Introduction to Computer Programming
Course Materials¶
How to access the programming environment?¶
The course's programming environment is conveniently accessible via a JupyterHub server, allowing remote access without the need to install any special software, thanks to Project Jupyter. This means you can easily write and run programs on your mobile devices using just a web browser.
Open the url of the JupyterHub server given in the course homepage. The first time you access the url, it opens a login page as shown in Figure 1:
- Enter your EID and Password in the fields
UsernameandPasswordrespectively. - Click the
Sign inbutton.
Figure 1:Login box
To access the Jupyter environment, simply log into the JupyterHub server and select the Default option from the list of available Jupyter servers. Click Start to begin your session. If the server is spawned successfully, the JupyterLab interface should appear. Each student will have their own Jupyter server, providing individual computer resources such as CPU and memory.
How to access the course materials?¶
Course materials are written in the form of Jupyter Notebooks. Jupyter Notebooks provide an interactive literate programming experience, which is a significant benefit for learners:
- Jupyter Notebooks allow programs to be mixed with other contents, including figures, videos, and formatted textual explanations.
- The notebooks can also run in a Jupyter server, which enables users to write and run their programs while adding formatted notes to it.
The recommended way is to follow the links to the notebooks on the course homepage as shown in Figure 2.
Figure 2:Links to lecture/lab notebooks on course homepage
The notebooks reside in a GitHub repository. The first time you access the notebook link, the following steps occur:
- Your Jupyter server is opened.
- The repository is cloned to the server as a local repository.
- The desired notebook is opened in the JupyterLab interface.
Afterwards, accessing a notebook link again will
- git-pulls new or existing files in the repository and
- merge them with the notebooks stored under the course folder
cs1302_xxxin your home directory without overwriting your changes.
Lab Assignments¶
How to complete a lab assignment?¶
The notebooks can be edited in JupyterLab to include your notes and answers for submission. If this is your first time using JupyterLab, take a look at the official video tutorial:
Official video tutorial on Jupyter
The Help menu gives more detailed references. For instance:
- Checkout the menu item
Show Keyboard Shortcutsand try some of the shortcuts to see their effect.Jupyter Referenceopens the user guide in a new tab. - Try the MyST Markdown syntax to format your notes.
In learning a new programming language, the first program to write is often the "Hello, World!" program, which says Hello to the world. As your first lab exercise, you will write such a program in python.
Complete the program in the solution cell to print the message Hello, World!.
Hint
One possible solution is:
def say_hello():
print("Hello, World!")
say_hello()Program 1:Python, "Hello, World!"
You must use a tab or 4 spaces to indent the second line of code print(...).
The following code cell is a solution cell. Since you are not expected to know python before, you can simply expand the hint above and copy the solution to the solution cell instead.
def say_hello():
# YOUR CODE HERE
raise NotImplementedError()
say_hello()It's important to follow certain guidelines when writing your answers or code in the notebooks:
- Only provide your answers in the cells that are designated for this purpose, which are usually labeled with
YOUR CODE HEREorYOUR ANSWER HERE. - For coding exercises, be sure to remove the line
raise NotImplementedError()from the cell before submitting your work. - Do not clone or duplicate the answer cells, as this can cause issues with version control and grading.
To test your program:
- Run your program by selecting the solution cell and press
Shift+Enter. - Then, run the following visible test to check whether your program prints the correct message.
# Run this test cell right after running your "Hello, World!" program.
import io
import sys
old_stdout, sys.stdout = sys.stdout, io.StringIO()
say_hello()
printed = sys.stdout.getvalue()
sys.stdout = old_stdout
assert printed == "Hello, World!\n"The test returns an assertion error if your program does not print the correct message.
- You can repeatedly modify your solution and run the test cell until your solution passes the test. There is no mark penalty in failing the test before submission.
- You should try to understand the error messages from a failed test.
- To assess your solution thoroughly, we will run new tests hidden from you after you have submitted your notebook. Therefore, you should ensure your solution works in general rather than just the visible tests.
- If you open the same notebook multiple times in different browser windows, be careful in making changes in different windows as you may overwrite your own changes.
- If your notebook fails to run any code, the kernel might have died. You can restart the kernel with
KernelRestart. If restarting fails, check your code cells to see if there is anything that breaks the kernel.
How to submit a notebook¶
- Late submissions will not be accepted without valid justifications.
- You can submit your assignment repeatedly before the deadline without penalty, so it is recommended to submit your assignment in advance. Please note that you are responsible for any issues related to failed submissions due to network outages that occur too close to the deadline.
- It is also important to make a record or backup of your submission that includes the submission timestamp. Double check to ensure that you have submitted the correct lab assignment, since multiple lab assignments may be open for submission at the same time.
You normally have at least 5 days to work on the lab after your lab session.
- You can check the due dates of all the labs from the course homepage.
- You may seek help from us or your classmates. However, you must write your own solution and indicate who your collaborators are by including their EIDs in a code cell:
COLLABORATORS = ["xfwong2", "mklee3"]
- Although the first Lab (
Lab0) does not count towards your final grade, you should still submit it, to get familiar with the procedure. - Lecture notebooks under the subfolders
Lecture*\need NOT be submitted. You only need to submit the lab notebooks underLab*\.
Nbgrader is the tool used for grading notebook assignments. It is well-integrated into the JupyterLab interface, allowing students to submit their notebooks directly through the JupyterHub server. Submitted notebooks can be both auto-graded with pre-defined test cases and manually graded with custom feedback. After grading is complete, you can check your scores and access the feedback using the same interface.
Before you submit, make sure everything runs as expected:
- Git-pull the notebooks (optional): Follow any one of the link on the course homepage to a notebook, which will git-pull any updates/corrections to (all) your notebooks.
- Save the notebook: Unsaved changes are not exported, even though they are in the memory.
- Restart the kernel:
KernelRestart Kernel...to have a clean state before running visible tests. - run all cells:
RunRun All Cellsto double check the results of the visible tests are as expected.
To submit your notebook:
- Select the menu item
NbgraderAssignment List. - Expand the Lab folder and click the
validatebutton next to the notebook(s) to check if all the visible tests pass. - Click
Submitto submit your notebook.
Your submission may not be graded under the following circumstances:
- If the notebook files have been renamed, for example,
Setup.ipynbbeing changed or copied toSetup (Copy).ipynb. - If an HTML file exists with the same name as a notebook, for example,
Setup.html. - If the file size exceeds
100MB. - If the code takes too long to run or requires an excessive amount of memory.
It is essential to ensure that your submission meets these guidelines to avoid any issues with grading.
Troubleshooting
If you believe your notebooks are corrupted,
- download/backup your existing notebooks,
- remove them from the
Lab*/folder, - click the git-pull links from the course homepage to re-pull the notebooks, and
- copy your solutions to the new notebooks.
You may also run the course notebooks outside the jupyterhub server and locally on your computer. For more details, see the course homepage.