Skip to content

Commit 060cf0e

Browse files
committed
Chapter 2 exercises
1 parent 8bd5629 commit 060cf0e

File tree

3 files changed

+80
-41
lines changed

3 files changed

+80
-41
lines changed

doc/source/0_preface.rst

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ year courses with the sole objective of teaching students to programme well.
3737
This book is the text for the second of these courses. Named "Principles of
3838
Programming", the course aims to take students with a knowledge of basic Python
3939
programming (functions, loops, plotting and so forth) and introduce them to
40-
higher level programming concepts. The course has also been taught to master's
41-
students in the Mathematical Institute at the University of Oxford.
40+
higher level programming concepts.
4241

4342
The objective of this course is to graduate better programmers. Material on
4443
new programming constructs and concepts is accompanied by chapters on good
@@ -68,11 +67,11 @@ This book is for anyone with mathematical, scientific, or engineering interests
6867
who would like to learn to be a more capable programmer. The mathematical
6968
examples assume that you know how to differentiate functions of one variable,
7069
but very little beyond that. Where examples or exercises employ other
71-
mathematics, such as cellular automata in :numref:`style` and groups in
72-
:numref:`abstract_data_types`, enough of the mathematics will be introduced
73-
that the reader should be able to understand the programming concept being
74-
explained, without necessarily understanding all of the mathematical details of
75-
the example.
70+
mathematics, such as cellular automata in :numref:`Chapter %s <style>` and
71+
groups in :numref:`Chapter %s <abstract_data_types>`, enough of the mathematics
72+
will be introduced that the reader should be able to understand the programming
73+
concept being explained, without necessarily understanding all of the
74+
mathematical details of the example.
7675

7776
This is not an introduction to basic Python: it's assumed that the reader knows
7877
the sort of basic Python usually covered in a first programming or
@@ -83,9 +82,9 @@ values, as well as dictionaries, lists, and tuples.
8382

8483
Many introductory Python courses exclusively use Jupyter notebooks, so nothing
8584
beyond that is assumed. Getting set up with a working Python installation is
86-
covered in :numref:`introduction` while the Python command line and using a
87-
text editor to create programmes in files are introduced from scratch in
88-
:numref:`programs_files`.
85+
covered in :numref:`Chapter %s <introduction>` while the Python command line
86+
and using a text editor to create programmes in files are introduced from
87+
scratch in :numref:`Chapter %s <programs_files>`.
8988

9089
How to use this book
9190
--------------------
@@ -123,18 +122,17 @@ The exercises
123122
.............
124123

125124
At the end of each chapter are exercises. These usually depend on a skeleton
126-
code which is available on GitHub. Sometimes you might be asked to complete a piece of code while on other
127-
occasions you'll need to write a whole Python module from scratch. Each set of
128-
exercises will come with a matching set of tests. These are small programs which
129-
check whether your code produces the correct responses to a range of inputs.
130-
Tests like this provide immediate feedback and enable you to know how you are
131-
doing. Links to the skeleton code for each chapter are provided at:
125+
code which is available on GitHub. Sometimes you might be asked to complete a
126+
piece of code while on other occasions you'll need to write a whole Python
127+
module from scratch. Each set of exercises will come with a matching set of
128+
tests. These are small programs which check whether your code produces the
129+
correct responses to a range of inputs. Tests like this provide immediate
130+
feedback and enable you to know how you are doing. Links to the skeleton code
131+
for each chapter are provided at:
132132

133133
`https://object-oriented-programming.github.io/edition1/exercises.html
134134
<https://object-oriented-programming.github.io/edition1/exercises.html>`__
135135

136-
The mechanism for accessing the exercises will be covered in
137-
:numref:`introduction`.
138136

139137
Conventions employed
140138
--------------------

doc/source/1_introduction.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ are:
7676
1. Python version 3.6 or later.
7777
2. Git (the revision control system we're going to use).
7878
3. A Python-aware text editor or :term:`integrated development
79-
environment`. Visual Studio Code is recommended, and all the
79+
environment` (IDE). Visual Studio Code is recommended, and all the
8080
instructions will assume that this is what you are using.
8181

8282
.. only:: book
@@ -104,6 +104,11 @@ are:
104104
Installation instructions for these pieces of code are provided `on this
105105
page <https://object-oriented-programming.github.io/installation.html>`__`.
106106

107+
This is not a course about Git, but a minimal familiarity with Git and GitHub
108+
will be needed in order to work with the examples. :numref:`Appendix %s <git>`
109+
provides an elementary introduction to these tools for readers not already
110+
familiar with them.
111+
107112
Python versions
108113
...............
109114

@@ -147,7 +152,7 @@ whole bunch of Python packages. It's highly desirable have a predictable
147152
programming environment in which the experiments you're doing don't interfere
148153
with anything else for which you might be using Python, and conversely which
149154
remains unaffected by any packages you may have installed elsewhere. This
150-
separation can be achieved by doing everything in a Python :term:`virtual
155+
separation can be achieved by working in a Python :term:`virtual
151156
environment`, or :term:`venv`.
152157

153158
A virtual environment is a folder containing a local installation of Python
@@ -164,7 +169,7 @@ call this anything you like. On my computer this is called
164169
:file:`principles_of_programming`. You can create this folder using the
165170
Windows File Explorer, Mac Finder, or by typing the following in a terminal:
166171

167-
.. code-block::
172+
.. code-block:: console
168173
169174
$ mkdir principles_of_programming
170175

doc/source/2_programs_in_files.rst

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Programs in files
55

66
In this chapter we will start to learn how to combine pieces of code into
77
larger units, and how to package up your code so that you or others can do the
8-
same. You will previously have written Python code in Jupyter notebooks, and
8+
same. You may previously have written Python code in Jupyter notebooks, and
99
possibly used an interactive Python environment such as IPython. Jupyter
1010
notebooks are an excellent platform for writing and documenting short pieces of
1111
code. However, they are much less good for writing code which is designed to be
@@ -327,7 +327,7 @@ want: it clearly separates the names in the module from the names we
327327
have defined ourselves, and makes it very obvious to a reader where
328328
the names come from. The downside is that names in namespaces can be
329329
quite long and cumbersome, which is particularly inconvenient if names
330-
are to be used frequently or in the middle of formulae: you probably
330+
are to be used frequently or in the middle of expressions: you probably
331331
don't really want to write :func:`math.sin` in every trig formula you
332332
ever write. One alternative is to rename the module on import. This is
333333
achieved using the keyword :keyword:`as <import>` in an import statement. For example,
@@ -449,7 +449,7 @@ they make up the Python package.
449449
This is not really a part of the package at all, but the
450450
:file:`my_package` folder needs to be in some folder, and this is a
451451
reminder that all your work should be in a revision control system
452-
such as :ref:`git <fons:git>`. It would be usual for
452+
such as :ref:`Git <git>`. It is usual for
453453
package folders to be contained immediately in the top level of
454454
the repository, in the manner shown here.
455455

@@ -927,7 +927,9 @@ Exercises
927927

928928
Before attempting the exercises, ensure that you have obtained the software
929929
tools described in :numref:`tools` and set up a working folder and
930-
:term:`virtual environment` as described in :numref:`venv`.
930+
:term:`virtual environment` as described in :numref:`venv`. If you're not
931+
already familiar with Git and GitHub then you will also need to work through
932+
:numref:`Appendix %s <git>` to learn enough to do the exercises.
931933

932934
.. .. panels::
933935
.. :card: quiz shadow
@@ -943,40 +945,68 @@ tools described in :numref:`tools` and set up a working folder and
943945
.. you will use for this course on your computer. Start with an overall folder
944946
.. for the module, and create a virtual environment in that module.
945947
948+
.. only:: book
949+
950+
.. raw:: latex
951+
952+
\clearpage
953+
946954
.. _course_repo:
947955

948956
.. proof:exercise::
949957
950-
Visit the `GitHub repository for these notes
951-
<https://github.com/object-oriented-python/object-oriented-programming>`__.
952-
Clone that git repository into your course folder, and install the Python
953-
package it contains into your virtual environment. Check that it has
954-
installed correctly by installing Pytest, and running:
958+
.. only:: not book
959+
960+
Visit the `GitHub repository for this book
961+
<https://github.com/object-oriented-python/object-oriented-programming>`__.
962+
Clone that git repository into your course folder, and install the Python
963+
package it contains into your virtual environment. Check that it has
964+
installed correctly by installing Pytest, and running:
965+
966+
.. only:: book
967+
968+
Visit the GitHub repository for this book. [#book_repo]_
969+
Clone that git repository into your working folder, and install the Python
970+
package it contains into your virtual environment. Check that it has
971+
installed correctly by installing Pytest, and running:
955972

956973
.. code-block:: console
957974
958975
(PoP_venv) $ pytest tests/test_fibonacci.py
959976
960-
You could also run iPython, import :mod:`fibonacci` and try out
977+
You could also run IPython, import :mod:`fibonacci` and try out
961978
:func:`fibonacci.fib <fibonacci.fibonacci.fib>` yourself.
962979

963980
.. proof:exercise::
964981
965-
Accept the `first GitHub Classroom assignment for this module
966-
<https://classroom.github.com/a/VltGa-Xl>`__ and clone it into your course folder. The assignment
967-
repository just contains a :file:`README` and some tests. Your job in the
968-
following exercises will be to populate it with the remaining content.
982+
.. only:: not book
983+
984+
Using the information on the `book website
985+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__
986+
create your first exercise repository for this module and clone it
987+
into your working folder. The exercise repository just contains a
988+
:file:`README` and some tests. Your job in the following exercises will be
989+
to populate it with the remaining content.
990+
991+
.. only:: book
992+
993+
Using the information on the `book website` [#exercise_page]_
994+
create your first exercise repository for this module and clone it
995+
into your working folder. The exercise repository just contains a
996+
:file:`README` and some tests. Your job in the following exercises will be
997+
to populate it with the remaining content.
998+
969999

9701000
.. proof:exercise::
9711001
9721002
Create a new Python :term:`package` named :mod:`math_utils` containing a
9731003
:term:`module` called :mod:`primes`. In the :mod:`primes` module define a
9741004
function :func:`isprime` which takes in a single integer argument and
975-
returns `True` or `False` depending on whether or not the argument is prime.
976-
There is no need to be sophisticated in the algorithm used to check for
977-
primeness, simply checking whether the number is zero modulo any of the
978-
integers less than its square root will be fine. Test your code by running
979-
the following in your week 2 exercise repository:
1005+
returns `True` or `False` depending on whether or not the argument is
1006+
prime. There is no need use a sophisticated algorithm, simply checking
1007+
whether the number is zero modulo any of the integers less than its square
1008+
root will be fine. Test your code by running the following in the exercise
1009+
repository:
9801010

9811011
.. code-block:: console
9821012
@@ -1029,4 +1059,10 @@ tools described in :numref:`tools` and set up a working folder and
10291059
<https://docs.python.org/3/reference/simple_stmts.html#import>`__
10301060
10311061
.. [#packaging] `https://packaging.python.org
1032-
<https://packaging.python.org/tutorials/packaging-projects/>`__
1062+
<https://packaging.python.org/tutorials/packaging-projects/>`__
1063+
1064+
.. [#book_repo] `https://github.com/object-oriented-python/object-oriented-programming
1065+
<https://github.com/object-oriented-python/object-oriented-programming>`__
1066+
1067+
.. [#exercise_page] `https://object-oriented-programming.github.io/edition1/exercises.html
1068+
<https://object-oriented-programming.github.io/edition1/exercises.html>`__

0 commit comments

Comments
 (0)