# Please run the contents of this cell.
# Select this cell and press Ctrl-Enter (or Command-Enter on mac).
from assertions import *
from test_cells import *Instructions with the Assignments
Dear student,
Welcome to the programming course “Programming with Python for Researchers – Python Fundamentals”. The assignments form the practical part of the course, next to the live coding. Because programming is doing, these assignments form a vital part of the final grade awarded for this course.
Please note that you are encouraged to work together on the assignments. Keep in mind, however, that understanding a program is much easier than writing a program yourself.
Jupyter Notebooks
The assignments will be made on a JupyterHub server in the form of Jupyter Notebooks. Jupyter Notebooks play a key role in data science, as is explained in this 2018 article in Nature.
If you are unfamiliar with Jupyter Notebooks, please have a look at this tutorial. If you do, please start with the section titled Creating a Notebook. Otherwise, you can also try the example below (not graded). This example has the same structure as all the assignments in this series.
The Assignment Structure
Each of the assignment notebook files contains a set of assignments, which are auto-graded. For each assignment, you should start by reading the instructions in the first cell. In the second cell, you are requested to program your solution by replacing these two lines:
# YOUR CODE HERE
raise NotImplementedError()with your own Python code. As long as you do not change these lines, your assignment function will raise a NotImplementedError error when run.
The third cell, which is (mostly) read-only, can be used to enter the requested values and test your assignment function. The fourth cell will be run by the auto-grading tool of the teacher. It will run a number of tests through your assignment function. Please run it yourself, as well. If you solved the assignment correctly, you will see a message like:
Well done! You seem to have solved assignment_1_1!
Debugging
Even in relatively small Python programs, you will discover that it is easy to make mistakes. To find out what the problem is, programmers often add print() statements at strategic places throughout their code, so that they can confirm whether their program actually reaches that location, and can inspect the current values of some variables there.
Example:
def my_function(a, b):
print('value of a is', a)
...Please use them often. They will not influence your (auto)grading.
Final instruction
Before you start solving the example assignment, please press Ctrl-Enter in the cell below (PC) or Command-Enter (Mac). It will load the modules needed for the testing and auto-grading the assignments. After you did, a number between the square brackets will appear in front of the cell, like - for example:
In [1]:Below the cell the following message will appear:
Assertions imported OK
Test cells imported OK
0.0 Example assignment
Every story has a beginning. This also holds for learning a programming language. It is common practice to have your first program show the following output on screen:
Hello, world!In our case, we would like the assignment function to return that phrase (a string).
To do so, change the function (defined with the def keyword) below into:
def assignment_0_0():
return 'Hello, world!'and press Crtl-Enter (PC) or Command-Enter (Mac). Check that a number appears between the square brackets in front of the cell.
Then, select the next (test) cell and press Crtl-Enter (PC) or Command-Enter (Mac) to run the function assignment_0_0() and have it print its important message.
Finally, run the assertion cell to see if the checking tool by the teacher will also approve of your solution. If it does, you can continue with the next assignment.
Good luck!
# Code for assignment 0.0
def assignment_0_0():
# YOUR CODE HERE
raise NotImplementedError()# Test for assignment 0.0
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_0_0(assignment_0_0)# Assertion for assignment 0.0
check_assertion(assignment_0_0)