Skip to content

Commit d0124e8

Browse files
committed
Several chapters' exercises.
1 parent 060cf0e commit d0124e8

File tree

5 files changed

+126
-67
lines changed

5 files changed

+126
-67
lines changed

doc/source/3_objects.rst

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ user might type in order to recreate the object. For example::
462462

463463
`type(self).__name__` simply evaluates to the class name, in this case
464464
`Polynomial`. This is better than hard-coding the class name because, as we will
465-
see in :numref:`week %s <inheritance>`, this implementation of
465+
see in :numref:`Chapter %s <inheritance>`, this implementation of
466466
:meth:`~object.__repr__` might well end up being inherited by a class with a
467467
different name. Notice that in order to help ensure consistency of
468468
representations we call :func:`repr` on the coefficients in this case, whereas
@@ -876,19 +876,27 @@ Glossary
876876
Exercises
877877
---------
878878

879-
.. only:: html
879+
.. .. only:: html
880880
881-
.. panels::
882-
:card: quiz shadow
881+
.. .. panels::
882+
.. :card: quiz shadow
883883
884-
.. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2054444_1
885-
:text: This week's quiz
886-
:classes: stretched-link
884+
.. .. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2054444_1
885+
.. :text: This week's quiz
886+
.. :classes: stretched-link
887887
888+
.. only:: not book
888889

889-
Obtain the `skeleton code for these exercises from GitHub Classroom <https://classroom.github.com/a/mElLR0AD>`__.
890-
The skeleton code contains a :mod:`polynomial` package with a version of
891-
the :class:`Polynomial` class.
890+
Using the information on the `book website
891+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__
892+
obtain the skeleton code for these exercises. The skeleton code contains a
893+
:mod:`polynomial` package with a version of the :class:`Polynomial` class.
894+
895+
.. only:: book
896+
897+
Using the information on the `book website` [#exercise_page]_,
898+
obtain the skeleton code for these exercises. The skeleton code contains a
899+
:mod:`polynomial` package with a version of the :class:`Polynomial` class.
892900

893901
.. proof:exercise::
894902
@@ -909,15 +917,16 @@ the :class:`Polynomial` class.
909917

910918
.. proof:exercise::
911919
912-
Define a function `derivative` in :file:`polynomials.py` which takes a
913-
:class:`Polynomial` and returns a new :class:`Polynomial` which is its
914-
derivative. Also define a :meth:`dx` method on the :class:`Polynomial` class
915-
which returns the derivative of that :class:`Polynomial`. Rather than
916-
duplicating code, you should implement the function by calling the method.
920+
Define a :meth:`dx` method on the :class:`Polynomial` class which returns a
921+
new :class:`Polynomial` which is the derivative of that
922+
:class:`Polynomial`. Also define a function `derivative` in
923+
:file:`polynomials.py` which takes a :class:`Polynomial` and returns its
924+
derivative. Rather than duplicating code, you should implement the function
925+
by calling the method.
917926

918927
.. proof:exercise::
919928
920-
Inside the exercise repository for this week, create a new :mod:`shape`
929+
Inside the exercise repository, create a new :mod:`shape`
921930
package containing a :mod:`circle` module.
922931

923932
1. Create a :class:`Circle` class
@@ -945,7 +954,10 @@ the :class:`Polynomial` class.
945954
.. proof:exercise::
946955
947956
Make the :mod:`circle` and :mod:`polynomial` packages installable. As with
948-
last week's exercise, pytest can't test this so you'll need to push to
957+
last chapter's exercise, Pytest can't test this so you'll need to push to
949958
GitHub and check that the autograding tests pass there.
950959

951-
960+
.. rubric:: Footnotes
961+
962+
.. [#exercise_page] `https://object-oriented-programming.github.io/edition1/exercises.html
963+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__

doc/source/4_style.rst

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,42 +1228,36 @@ Glossary
12281228
Exercises
12291229
---------
12301230

1231-
.. only:: html
1231+
.. .. only:: html
12321232
1233-
.. panels::
1234-
:card: quiz shadow
1233+
.. .. panels::
1234+
.. :card: quiz shadow
12351235
1236-
.. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2070388_1&mode=cpview
1237-
:text: This week's quiz
1238-
:classes: stretched-link
1236+
.. .. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2070388_1&mode=cpview
1237+
.. :text: This week's quiz
1238+
.. :classes: stretched-link
12391239
12401240
.. proof:exercise::
12411241
12421242
Install flake8, pep8-naming, and flake8-docstrings.
12431243
Configure your Python editor to use flake8.
12441244

1245-
The `skeleton code for this chapter's exercises on GitHub Classroom
1246-
<https://classroom.github.com/a/GCKdXtVA>`__ contains a package :mod:`life`
1247-
which implements Conway's Game of Life. Accept the assignment, and clone the
1248-
repository. Install the package in editable mode. This will also install some
1249-
additional packages that the :mod:`life` package depends on. This is achieved
1250-
using an additional argument to :func:`setuptools.setup`.
1245+
.. only:: not book
1246+
1247+
The skeleton code on GitHub for this chapter's exercises contains a package
1248+
:mod:`life` which implements Conway's Game of Life. Using the information on the `book website
1249+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__
1250+
obtain the skeleton code for these exercises. Clone the repository into
1251+
your working folder and install the package in editable mode.
1252+
1253+
.. only:: book
1254+
1255+
The skeleton code on GitHub for this chapter's exercises contains a package
1256+
:mod:`life` which implements Conway's Game of Life. Using the information
1257+
on the book website [#exercise_page]_
1258+
obtain the skeleton code for these exercises. Clone the repository into
1259+
your working folder and install the package in editable mode.
12511260

1252-
.. code-block:: python3
1253-
:caption: `setup.py` for the :mod:`life` package. The `install_requires`
1254-
parameter is used to install other packages that :mod:`life` needs.
1255-
1256-
from setuptools import setup, find_packages
1257-
setup(
1258-
name="life",
1259-
version="0.1",
1260-
packages=find_packages(),
1261-
install_requires=[
1262-
"matplotlib",
1263-
"scipy",
1264-
"numpy"
1265-
]
1266-
)
12671261

12681262
A couple of example scripts are provided which demonstrate the game of life.
12691263
This one shows a glider flying across the board:
@@ -1349,7 +1343,9 @@ neverending sequence of gliders:
13491343
two parameters, a :class:`Pattern` and a pair of integers representing a
13501344
square on the game board. The method should modify the game board so as to
13511345
insert the pattern provided at a location centred on the location given by
1352-
the pair of integers.
1346+
the pair of integers. :numref:`glider_inserted` illustrates this operation.
1347+
1348+
.. _glider_inserted:
13531349

13541350
.. figure:: images/glider_inserted.png
13551351
:width: 60%
@@ -1376,3 +1372,6 @@ six oscillating blinkers:
13761372
such, they are usually of little interest to most Python
13771373
users. However the PEPs having to do with style have wider
13781374
significance.
1375+
1376+
.. [#exercise_page] `https://object-oriented-programming.github.io/edition1/exercises.html
1377+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__

doc/source/5_abstract_data_types.rst

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -828,20 +828,29 @@ Glossary
828828
Exercises
829829
---------
830830

831-
.. panels::
832-
:card: quiz shadow
831+
.. .. panels::
832+
.. :card: quiz shadow
833833
834-
.. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2077681_1&mode=cpview
835-
:text: This week's quiz
836-
:classes: stretched-link
834+
.. .. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2077681_1&mode=cpview
835+
.. :text: This week's quiz
836+
.. :classes: stretched-link
837837
838+
.. only:: not book
838839

839-
Obtain the `skeleton code for these exercises from GitHub classroom
840-
<https://classroom.github.com/a/eHigwP_C>`__. You will also need to install the pytest-timeout package.
840+
Using the information on the `book website
841+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__
842+
obtain the skeleton code for these exercises. You will also need to install
843+
the pytest-timeout package.
844+
845+
.. only:: book
846+
847+
Using the information on the book website [#exercise_page]_ obtain the
848+
skeleton code for these exercises. You will also need to install the
849+
pytest-timeout package.
841850

842851
.. proof:exercise::
843852
844-
In this week's skeleton repository, create a :term:`package` called
853+
In the exercise repository, create a :term:`package` called
845854
:mod:`adt_examples` with a :term:`module` called
846855
:mod:`adt_examples.fibonacci`. Make the package installable and install it
847856
in editable mode. Create a class :class:`Fib` implementing the iterator
@@ -863,7 +872,7 @@ Obtain the `skeleton code for these exercises from GitHub classroom
863872

864873
.. proof:exercise::
865874
866-
In this week's skeleton repository, create a :term:`module`
875+
In the exercise repository, create a :term:`module`
867876
:mod:`adt_examples.rpcalc` containing a class :class:`RPCalc` implementing a
868877
reverse Polish calculator. The calculator should have the following methods:
869878

@@ -891,7 +900,7 @@ Obtain the `skeleton code for these exercises from GitHub classroom
891900

892901
.. proof:exercise::
893902
894-
In this week's skeleton repository, create a :term:`module`
903+
In the exercise repository, create a :term:`module`
895904
:mod:`adt_examples.deque` containing a class :class:`Deque` implementing a
896905
:term:`deque`. Your implementation should use a ring buffer implemented
897906
as a Python list. In order to make things somewhat simpler, we will use a
@@ -950,3 +959,8 @@ Obtain the `skeleton code for these exercises from GitHub classroom
950959
.. note::
951960

952961
You may not use :class:`collections.deque` to implement this exercise.
962+
963+
.. rubric:: Footnotes
964+
965+
.. [#exercise_page] `https://object-oriented-programming.github.io/edition1/exercises.html
966+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__

doc/source/6_exceptions.rst

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,17 +797,33 @@ Glossary
797797
in each :term:`stack frame`, with the current frame at the
798798
bottom and the outermost frame at the top.
799799

800+
.. only:: book
801+
802+
.. raw:: latex
803+
804+
\clearpage
805+
800806
Exercises
801807
---------
802808

803-
.. panels::
804-
:card: quiz shadow
809+
.. .. panels::
810+
.. :card: quiz shadow
811+
812+
.. .. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2083792_1&mode=cpview
813+
.. :text: This week's quiz
814+
.. :classes: stretched-link
805815
806-
.. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2083792_1&mode=cpview
807-
:text: This week's quiz
808-
:classes: stretched-link
816+
.. Obtain the `skeleton code for these exercises from GitHub classroom <https://classroom.github.com/a/JqFsKmoR>`__.
817+
.. only:: not book
809818

810-
Obtain the `skeleton code for these exercises from GitHub classroom <https://classroom.github.com/a/JqFsKmoR>`__.
819+
Using the information on the `book website
820+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__
821+
obtain the skeleton code for these exercises.
822+
823+
.. only:: book
824+
825+
Using the information on the book website [#exercise_page]_ obtain the
826+
skeleton code for these exercises.
811827

812828
.. proof:exercise::
813829
@@ -825,7 +841,7 @@ Obtain the `skeleton code for these exercises from GitHub classroom <https://cla
825841
iteration should fail if :math:`n` exceeds a user-specified number of
826842
iterations.
827843

828-
The skeleton code for this week contains a function
844+
The skeleton code for this chapter contains a function
829845
:func:`nonlinear_solvers.solvers.newton_raphson` which takes as arguments a
830846
function, its derivative and a starting point for the iteration. It can also
831847
optionally be passed a value for :math:`\epsilon` and a maximum number of
@@ -866,3 +882,6 @@ Obtain the `skeleton code for these exercises from GitHub classroom <https://cla
866882

867883
.. [#function] "Function call" here includes :term:`method` calls and
868884
operations implemented using a :term:`special method`.
885+
886+
.. [#exercise_page] `https://object-oriented-programming.github.io/edition1/exercises.html
887+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__

doc/source/7_inheritance.rst

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ Consider the :meth:`__str__` method of :class:`~example_code.groups.Group`:
517517
:lineno-start: 19
518518
519519
def __str__(self):
520+
"""Return a string in the form symbol then group parameter."""
520521
return f"{self.symbol}{self.n}"
521522
522523
This code uses `self.symbol`, but this attribute isn't defined anywhere on
@@ -772,15 +773,24 @@ Glossary
772773
Exercises
773774
---------
774775

775-
Obtain the `skeleton code for these exercises from GitHub classroom <https://classroom.github.com/a/VXIC_gES>`__.
776+
.. only:: not book
777+
778+
Using the information on the `book website
779+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__
780+
obtain the skeleton code for these exercises.
781+
782+
.. only:: book
783+
784+
Using the information on the book website [#exercise_page]_ obtain the
785+
skeleton code for these exercises.
776786

777787
.. proof:exercise::
778788
779789
The symmetric group over `n` symbols is the group whose members are all the
780790
permutations of `n` symbols and whose group operation is the composition of
781791
those permutations: :math:`a \cdot b = a(b)`.
782792

783-
In this week's skeleton code repository, create package called
793+
In the exercise repository, create package called
784794
:mod:`groups` containing a module called :mod:`symmetric_groups`. Define a
785795
new class :class:`SymmetricGroup` which inherits from
786796
:class:`example_code.groups.Group` and implements the symmetric group of
@@ -799,7 +809,7 @@ Obtain the `skeleton code for these exercises from GitHub classroom <https://cla
799809

800810
You will need to :keyword:`import` :class:`example_code.groups.Group`
801811
from the `object_oriented_programming` repository that you installed
802-
:ref:`in week 2 <course_repo>`. You should also `git pull` in that
812+
:ref:`in Chapter 2 <course_repo>`. You should also `git pull` in that
803813
repository in order to get any changes that have happened in the
804814
intervening period.
805815

@@ -815,7 +825,7 @@ Obtain the `skeleton code for these exercises from GitHub classroom <https://cla
815825
:class:`set` class which are only valid for values which pass a certain
816826
test. For example, one might have a set which can only contain integers.
817827

818-
1. In this week's repository, create a package called :mod:`sets` containing a
828+
1. In the exercise repository, create a package called :mod:`sets` containing a
819829
module `verified_sets`. Create a subclass of the inbuilt :class:`set`,
820830
:class:`sets.verified_sets.VerifiedSet`. :class:`VerifiedSet` will itself
821831
be the parent of other classes which have particular verification rules.
@@ -851,3 +861,8 @@ Obtain the `skeleton code for these exercises from GitHub classroom <https://cla
851861
should create a new exception :class:`UniquenessError`, a subclass of
852862
:class:`KeyError`. :class:`UniqueSet._verify` should raise this if an
853863
operation would add a duplicate value to the :class:`UniqueSet`.
864+
865+
.. rubric:: Footnotes
866+
867+
.. [#exercise_page] `https://object-oriented-programming.github.io/edition1/exercises.html
868+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__

0 commit comments

Comments
 (0)