-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add solve functionality. * Add solutions creation to tutorial. * Add solve cli command. * Run black. * Fix error in docs.
- Loading branch information
1 parent
2e6a5a4
commit 9bf0606
Showing
6 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
solve an assignment | ||
=================== | ||
|
||
You can solve an assignment in 1 or 2 ways: | ||
|
||
1. Using the command line tool. | ||
2. Using :code:`nbchkr` as a library. | ||
|
||
Using the command line tool | ||
--------------------------- | ||
|
||
Given a source assignment :code:`main.ipynb`:: | ||
|
||
$ nbchkr solve --source main.ipynb --output solution.ipynb | ||
|
||
This creates :code:`solution.ipynb` with relevant cells removed which can | ||
then be distributed to students. | ||
|
||
Using :code:`nbchkr` as a library | ||
--------------------------------- | ||
|
||
All of :code:`nbchkr`'s functionality is exposed to the user as a library. | ||
|
||
Importing the relevant libraries:: | ||
|
||
>>> import pathlib | ||
>>> import re | ||
>>> import nbchkr.utils | ||
|
||
Reading in the source notebook :code:`main.ipynb` and removing relevant cells. | ||
We here use a regex that matches nothing for the solutions (as we want them to | ||
stay in place):: | ||
|
||
>>> nb_path = pathlib.Path("main.ipynb") | ||
>>> solution_regex = re.compile('$^') | ||
>>> nb_node = nbchkr.utils.read(nb_path=nb_path) | ||
>>> student_nb = nbchkr.utils.remove_cells(nb_node=nb_node, solution_regex=solution_regex) | ||
|
||
Writing the assignment notebooks :code:`assignment.ipynb`:: | ||
|
||
>>> output_path = pathlib.Path("solution.ipynb") | ||
>>> nbchkr.utils.write(output_path=output_path, nb_node=nb_node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "metadata": {}, "source": "# Class assignment\n\nWe will use this assignment to solidify our understanding of using Python to\ncarry out some numerical operations and also write functions.\n\nUse this notebook to write your answers in the cells as instructed, do your\nbest not to delete any of the cells that are already there.\n\n## Question one.\n\nUse python to obtain the remainder when dividing 21 by 5:\n\n\\\\[21 \\mod 5\\\\]"}, {"cell_type": "code", "execution_count": 1, "metadata": {"tags": ["answer:q1"]}, "outputs": [{"data": {"text/plain": "1"}, "execution_count": 1, "metadata": {}, "output_type": "execute_result"}], "source": "### BEGIN SOLUTION\n21 % 5\n### END SOLUTION"}, {"cell_type": "markdown", "metadata": {}, "source": "## Question two.\n\nWrite a python function `get_remainder(m, n)` that returns the remainder\nthe remainder when dividing \\\\(m\\\\) by \\\\(n\\\\).\n\n\\\\[m \\mod n\\\\]"}, {"cell_type": "code", "execution_count": 4, "metadata": {"tags": ["answer:q2"]}, "outputs": [], "source": "def get_remainder(m, n):\n ### BEGIN SOLUTION\n \"\"\"\n This function returns the remainder of m when dividing by n\n \"\"\"\n return m % n\n ### END SOLUTION"}], "metadata": {"celltoolbar": "Tags", "kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.1"}}, "nbformat": 4, "nbformat_minor": 4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters