Skip to content

Commit b9b94af

Browse files
committed
added conditionals to control flow part
1 parent 2c9aa20 commit b9b94af

File tree

15 files changed

+360
-47
lines changed

15 files changed

+360
-47
lines changed

bibliography/bibliography.bib

+16-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ @string { a_devito_zachary
8080
@string { a_dimitrovic_slobodan = "Slobodan Dmitrovi{\'c}" }
8181
@string { a_dubourg_vincent = "Vincent Dubourg" }
8282
@string { a_duchesnay_edouard = "Edouard Duchesnay" }
83+
@string { a_editors_of_encyclopaedia_britannica = "The Editors of Encyclopaedia Britannica" }
8384
@string { a_eglen_stephen_j = "Stephen J.\ Eglen" }
8485
@string { a_fang_lu = "Lu Fang" }
8586
@string { a_feng_yu = "Yu Feng" }
@@ -92,6 +93,7 @@ @string { a_fufezan_christian
9293
@string { a_garcia_alessandro = "Alessandro Garcia" }
9394
@string { a_garnett_roman = "Roman Garnett" }
9495
@string { a_gatto_laurent = "Laurent Gatto" }
96+
@string { a_gaur_aakanksha = "Aakanksha Gaur" }
9597
@string { a_gerard_marchant_pierre = "Pierre G{\'e}rard{-}Marchant" }
9698
@string { a_ghemawat_sanjay = "Sanjay Ghemawat" }
9799
@string { a_gimelshein_natalia = "Natalia Gimelshein" }
@@ -155,11 +157,13 @@ @string { a_levenberg_josh
155157
@string { a_levkivskyi_ivan = "Ivan Levkivskyi" }
156158
@string { a_lin_zeming = "Zeming Lin" }
157159
@string { a_liu_yuxi = "Yuxi Liu" }
160+
@string { a_lotha_gloria = "Gloria Lotha" }
158161
@string { a_loy_marc = "Marc Loy" }
159162
@string { a_lun_anthony_w_c = "Anthony W.-C.\ Lun" }
160163
@string { a_mann_samuel = "Samuel Mann" }
161164
@string { a_marsh_charlie = "Charlie Marsh" }
162165
@string { a_massa_francisco = "Francisco Massa" }
166+
@string { a_matthias_meg = "Meg Matthias" }
163167
@string { a_maxwell_aaron = "Aaron Maxwell" }
164168
@string { a_mayorov_nikolay = "Nikolay Mayorov" }
165169
@string { a_mcintosh_shane = "Shane McIntosh" }
@@ -205,6 +209,7 @@ @string { a_reddy_tyler
205209
@string { a_ribeiro_antonio_h = "Ant{\^o}nio H.\ Ribeiro" }
206210
@string { a_rivest_ronald_linn = "Ronald Linn Rivest" }
207211
@string { a_robertson_edmund_f = "Edmund F.\ Robertson" }
212+
@string { a_rodriguez_emily = "Emily Rodriguez" }
208213
@string { a_roscoe_timothy = "Timothy Roscoe" }
209214
@string { a_rosenblatt_bill = "Bill Rosenblatt" }
210215
@string { a_roth_ori = "Ori Roth" }
@@ -215,6 +220,7 @@ @string { a_sagher_yoram
215220
@string { a_salakoski_tapio = "Tapio Salakoski" }
216221
@string { a_salvaneschi_guido = "Guido Salvaneschi" }
217222
@string { a_scipy_1 = "{{SciPy 1.0 Contributors}}" }
223+
@string { a_setia_veenu = "Veenu Setia" }
218224
@string { a_shalev_shwartz_shai = "Shai Shalev{-}Shwartz" }
219225
@string { a_shen_kangshen = "Shen Kangshen" }
220226
@string { a_sheppart_kevin = "Kevin Sheppard" }
@@ -890,6 +896,15 @@ @book{DBvR2024ITN
890896
isbn = {9781836208631},
891897
}
892898

899+
@incollection{EOEBSRGML2024LY,
900+
author = a_editors_of_encyclopaedia_britannica # and # a_setia_veenu # and # a_rodriguez_emily # and # a_gaur_aakanksha # and # a_matthias_meg # and # a_lotha_gloria,
901+
title = {Leap Year},
902+
booktitle = {Encyclopaedia Britannica},
903+
date = {2024-08-20},
904+
url = {https://www.britannica.com/science/leap-year-calendar},
905+
urldate = {2024-08-29},
906+
}
907+
893908
@inbook{F2011TTOEAP,
894909
author = a_filaseta_michael,
895910
booktitle = {Math~785: Transcendental Number Theory},
@@ -993,7 +1008,7 @@ @book{H2023ABGTP3P
9931008

9941009
@book{H2024PBOTTCODDSIPP33,
9951010
author = a_hunner_trey,
996-
title = {\python\ Big~{O}: The Time Complexities of Different Data Structures in \python; \python~3.8-3.12},
1011+
title = {\python\ Big~\bigO: The Time Complexities of Different Data Structures in \python; \python~3.8-3.12},
9971012
date = {2024-04-16},
9981013
publisher = p_python_morsels,
9991014
address = pa_python_morsels,

notation/terms.sty

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See \cref{sec:howFloatingPointNumbersWork}.%
1818
name={docstring},%
1919
description={%
2020
Docstrings are special string constants in \python\ that contain documentation for modules or functions~\cite{PEP257}. %
21-
They must be delimited by~\pythonil{"""..."""}\pythonIdx{\textquotedbl\textquotedbl\textquotedbl}~\cite{PEP257,PEP8}.%
21+
They must be delimited by~\pythonil{"""..."""}\pythonIdx{\textquotedbl\textquotedbl\textquotedbl\idxdots\textquotedbl\textquotedbl\textquotedbl}~\cite{PEP257,PEP8}.%
2222
}%
2323
}%
2424
%
@@ -49,7 +49,7 @@ name={f-string},%
4949
plural={f-strings},%
5050
sort={f-string},
5151
description={%
52-
is a special string in \python, which delimited by \pythonil{f"..."} which can contain expressions in curly braces like \pythonil{f"a\{6-1\}b"} that are then turned to text via \pgls{strinterpolation}, which turns the string to~\pythonil{"a5b"}. %
52+
is a special string in \python, which delimited by \pythonil{f"..."}\pythonIdx{f\textquotedbl\idxdots\textquotedbl} which can contain expressions in curly braces like \pythonil{f"a\{6-1\}b"} that are then turned to text via \pgls{strinterpolation}, which turns the string to~\pythonil{"a5b"}. %
5353
f\nobreakdash-strings are discussed in \cref{sec:fstrings}.%
5454
}%
5555
}%

styles/listing.sty

+17-12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ keywordstyle={[2]\color{listing-keyword-2}\bfseries},%
3131
keywordstyle={[3]\color{listing-keyword-3}\bfseries\itshape},%
3232
commentstyle=\itshape\color{listing-comment},%
3333
stringstyle=\color{listing-string},%
34+
showspaces=false,%
35+
showtabs=false,%
3436
showstringspaces=false,%
3537
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},%
3638
%
@@ -192,16 +194,6 @@ language=bash,%
192194
\gitCode{#1}{#2}{}{#3}{#4}{,style=bash_style}%
193195
}%
194196
%
195-
%
196-
%%
197-
%% Load a local listing.
198-
%% #1 the local path
199-
%% #2 the label (lst: will be pre-pended)
200-
%% #3 the caption
201-
\protected\gdef\relCode#1#2#3{%
202-
\lstinputlisting[float,label={lst:#2},caption={#3}]{\currentDir/#1}}%
203-
%
204-
%%
205197
%% Use latexgit to place a listing with program output.
206198
%% #1 the git repository
207199
%% #2 the local path
@@ -232,7 +224,7 @@ language=bash,%
232224
%
233225
\begin{figure}[tb]%
234226
\centering%
235-
\lstinputlisting[label={lst:#5},caption={#6~(stored in file~\href{\csname @pwp@gitUrl:lst:#5\endcsname}{\textil{#3}}; output in~\cref{exec:#5})}]{\csname @pwp@gitFile:lst:#5\endcsname}%
227+
\lstinputlisting[label={lst:#5},style=python_style,caption={#6~(stored in file~\href{\csname @pwp@gitUrl:lst:#5\endcsname}{\textil{#3}}; output in~\cref{exec:#5})}]{\csname @pwp@gitFile:lst:#5\endcsname}%
236228
%
237229
$\downarrow$~~\expandafter\bashil{python3 #3}~~$\downarrow$%
238230
%
@@ -260,10 +252,23 @@ $\downarrow$~~\expandafter\bashil{python3 #3}~~$\downarrow$%
260252
%
261253
\begin{figure}[tb]%
262254
\centering%
263-
\lstinputlisting[label={lst:#5},caption={#6~(stored in file~\href{\csname @pwp@gitUrl:lst:#5\endcsname}{\textil{#3}}; output in~\cref{exec:#5})}]{\csname @pwp@gitFile:lst:#5\endcsname}%
255+
\lstinputlisting[label={lst:#5},style=python_style,caption={#6~(stored in file~\href{\csname @pwp@gitUrl:lst:#5\endcsname}{\textil{#3}}; output in~\cref{exec:#5})}]{\csname @pwp@gitFile:lst:#5\endcsname}%
264256
%
265257
$\downarrow$~~\expandafter\bashil{python3 #3}~~$\downarrow$%
266258
%
267259
\lstinputlisting[label={exec:#5},style=text_style,caption={The standard output and error as well as the exit code of the program~\href{\csname @pwp@gitUrl:lst:#5\endcsname}{\textil{#3}} given in~\cref{lst:#5}.}]{\csname @pwp@gitFile:exec:#5\endcsname}%
268260
\end{figure}%
269261
}%
262+
%
263+
%%
264+
%% The python syntax environment.
265+
\lstnewenvironment{pythonSyntax}[1][true]{%
266+
\let\@old@lst@visiblespace\lst@visiblespace%
267+
\def\lst@visiblespace{{\color{Gray}\@old@lst@visiblespace}}%
268+
\lstset{%
269+
style=python_style,%
270+
showspaces=#1%
271+
}}{%
272+
\let\lst@visiblespace\@old@lst@visiblespace%
273+
}%
274+
%

styles/myindex.sty

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@
1111
\protected\gdef\pythonilIdx#1{\index[python]{#1}\pythonil{#1}}%
1212
\makeindex%
1313
%
14+
%% dots without end-of-sentence spacing at the end
15+
\protected\gdef\idxdots{%
16+
.\kern\fontdimen3\font%
17+
.\kern\fontdimen3\font%
18+
.\@\strut}%
19+
%

text/main/basics/basics.tex

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
\item use some tools to help us looking for errors%
88
\end{itemize}%
99
%
10+
In particular, we will learn how to use the \python\ console and the editor \pycharm.
11+
We will learn about the most important simple datatypes in \python, such as integer numbers, floating point numbers, strings, and Boolean values.
12+
We will learn how to store values in variables.
13+
And we will learn about the most important collection datatypes offered by \python, namely lists, tuples, sets, and dictionaries.%
14+
%
1015
\hinput{gettingStarted}{gettingStarted.tex}%
1116
\hinput{simpleDataTypesAndOperations}{simpleDataTypesAndOperations.tex}%
1217
\hinput{variables}{variables.tex}%

text/main/basics/collections/collections.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
The mathematical notion of sets is implemented in the \python\ datatype \pythonil{set}.
2424
A set can contain each element at most once.
2525
The methods for modifying sets and for checking whether elements are contained in them are particularly fast.
26-
Sets are created using curly braces, i.e., \pythonil{my_set = \{1.2, 2.3, 4.5, 2.3\}} would create the set \pythonil{my_set} with the three numbers \pythonil{1.2}, \pythonil{2.3}, and~\pythonil{4.5}.
26+
Sets are created using curly braces, i.e., \pythonil{my_set = \{1.2, 2.3, 4.5, 2.3\}}\pythonIdx{\textbraceleft\idxdots\textbraceright!set} would create the set \pythonil{my_set} with the three numbers \pythonil{1.2}, \pythonil{2.3}, and~\pythonil{4.5}.
2727
Notice that \pythonil{2.3} would appear only once in the set.
2828
Sets cannot be indexed, but like lists and tuples they support the \pythonil{in} operator and \pythonil{1.2 in my_set} returns \pythonil{True} while \pythonil{1.3 in my_set} is \pythonil{False}.
2929
We will discuss sets in \cref{sec:sets}.
3030

3131
Finally, dictionaries are mappings between keys and values, similar to hash tables in other programming languages.
3232
They, too, are created using curly braces which, however, contain key-value pairs.
33-
In other words, \pythonil{my_dict = \{"pi": 3.1416, "e": 2.7183, "phi": 1.618\}} creates a dictionary which maps the strings \pythonil{"pi"}, \pythonil{"e"}, and \pythonil{"phi"} to the values \pythonil{3.1416}, \pythonil{2.7183}, and~\pythonil{1.618}, respectively.
33+
In other words, \pythonil{my_dict = \{"pi": 3.1416, "e": 2.7183, "phi": 1.618\}}\pythonIdx{\textbraceleft\idxdots\textbraceright!dict} creates a dictionary which maps the strings \pythonil{"pi"}, \pythonil{"e"}, and \pythonil{"phi"} to the values \pythonil{3.1416}, \pythonil{2.7183}, and~\pythonil{1.618}, respectively.
3434
The value of a key can be retrieved using the square-bracket indexing, i.e., \pythonil{my_dict["e"]} would return \pythonil{2.7183}.
3535
They are discussed in \cref{sec:dictionaries}.%
3636
%

text/main/basics/collections/dictionaries/dictionaries.tex

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
An example for using dictionaries in \python.}%
66
%
77
Dictionaries in \python\ are containers that store key-value pairs.
8-
The value associated with a given key is accessed via the \pythonilIdx{[...]}-based indexing.
8+
The value associated with a given key is accessed via the \pythonil{[...]}\pythonIdx{[\idxdots]}-based indexing.
99
The keys are unique and can be of an arbitrary type, as long as they are immutable.
1010
The concept of dictionary is also known as hash table or hash map in other languages or domains.
1111
Sets and dictionaries in \python\ are implemented using similar datastructures~\cite{B2023T}, namely hash tables~\cite{K1998SAS,CLRS2009ITA,SKS2019DSC}, and thus exhibit similar performance.%
1212
%
1313
\begin{sloppypar}%
1414
\cref{lst:dicts:dicts_1} shows some examples of how we can use dictionaries.
15-
A dictionary can be created again using the \pythonilIdx{\{...\}} syntax, however, this time, we place comma-separated \pythonil{key-value} pairs within the curly braces.
15+
A dictionary can be created again using the \pythonil{\{...\}}\pythonIdx{\textbraceleft\idxdots\textbraceright!dict} syntax, however, this time, we place comma-separated \pythonil{key-value} pairs within the curly braces.
1616
The type hints for dictionaries\pythonIdx{dict!type hint} is \pythonil{dict[keyType][valueType]}, where \pythonil{keyType} is the type for the keys and \pythonil{valueType} is the type for the values.
1717
The line \pythonil{num_str: dict[int, str] = \{2: "two", 1: "one", 3: "three", 4: "four"\}} therefore creates a new dictionary and stores it in the variable \pythonil{num_str}.
1818
The type-hint of the variable states that it can point only to dictionaries that have integers as keys and strings as values.
@@ -60,8 +60,8 @@
6060
%
6161
\begin{sloppypar}%
6262
As stated before, the types for keys and values in a dictionary can be chosen arbitrary, with the limitation that keys must be immutable.
63-
We now create the empty dictionary \pythonil{str_num: dict[str, int] = \{\}}\pythonIdx{\{\}}\pythonIdx{dict!empty}.\footnote{%
64-
Using the \pythonil{dict()}\pythonIdx{dict!empty} without arguments has the same effect, but several \pglspl{linter} discourage this and encourage using \pythonilIdx{\{\}} instead.%
63+
We now create the empty dictionary \pythonil{str_num: dict[str, int] = \{\}}\pythonIdx{\textbraceleft\textbraceright}\pythonIdx{dict!empty}.\footnote{%
64+
Using the \pythonil{dict()}\pythonIdx{dict!empty} without arguments has the same effect, but several \pglspl{linter} discourage this and encourage using \pythonil{\{\}}\pythonIdx{\textbraceleft\textbraceright} instead.%
6565
}
6666
Notice that only due to the type hint \pythonil{dict[str, int]}, other programmers and static type-checking tools can know at this point that we intend to use strings as keys and integers as values in this new dictionary.
6767
The \pythonilIdx{update}\pythonIdx{dict!update} method allows us to append the values of an existing dictionary to a given dictionary.

text/main/basics/collections/lists/lists.tex

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
A first example for using lists in \python: creating, indexing, printing of and appending elements and other lists to lists.}%
1111
%
1212
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{lists_2.py}{--args format}{lists:lists_2}{%
13-
A second example for using lists in \python: inserting and deleting elemensts, sorting and reversing lists.}%
13+
A second example for using lists in \python: inserting and deleting elements, sorting and reversing lists.}%
1414
%
1515
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{lists_3.py}{--args format}{lists:lists_3}{%
1616
A third example for using lists in \python: slicing, adding, and multiplying lists.}%
1717
%
1818
In \cref{lst:lists:lists_1}, we provide some first examples for using lists.
19-
A list can be defined by simply writing its contents, separated by~\pythonilIdx{,} inside square brackets~\pythonilIdx{[...]}.
19+
A list can be defined by simply writing its contents, separated by~\pythonilIdx{,} inside square brackets~\pythonil{[...]}\pythonIdx{[\idxdots]}.
2020
\pythonil{["apple", "pear", "orange"]} creates a list with three elements, namely the strings \pythonil{"apple"}, \pythonil{"pear"}, and~\pythonil{"orange"}.
2121
If we want to store a list in a variable, then we can use the type hint~\pythonil{list[elementType]}\pythonIdx{list!type hint} where \pythonil{elementType} is to be replaced with the type of the list elements.
2222
\pythonil{fruits: list[str] = ["apple", "pear", "orange"]} therefore creates the list \pythonil{fruits} with the contents listed above.
@@ -104,7 +104,7 @@
104104

105105
In \cref{sec:strBasicOperations}, we discussed string slicing.
106106
Lists can be sliced in pretty much the same way\pythonIdx{list!slicing}\pythonIdx{slicing}~\cite{PSF2024S}.
107-
When slicing a list~\pythonil{l} or a string, you can provide either two or three values in the square brackets\pythonIdx{[...]}, i.e., either do~\pythonil{l[i:j]} or \pythonil{l[i:j:k]}.
107+
When slicing a list~\pythonil{l} or a string, you can provide either two or three values in the square brackets\pythonIdx{[\idxdots]}\pythonIdx{[i:j:k]}, i.e., either do~\pythonil{l[i:j]}\pythonIdx{[i:j]}\pythonIdx{slicing} or \pythonil{l[i:j:k]}.
108108
If \pythonil{j < 0}, then it is replaced with~\pythonil{len(l) - j}.
109109
In both the two and three indices case, \pythonil{i} is the inclusive start index and \pythonil{j} is the exclusive end index, i.e., all elements with index~\pythonil{m} such that \pythonil{i <= m < j}.
110110
In other words, the slice will contain elements from~\pythonil{l} whose index is between~\pythonil{i} and~\pythonil{j}, including the element at index~\pythonil{i} but \emph{not} including the element at index~\pythonil{j}.
@@ -140,6 +140,7 @@
140140
\endhsection%
141141
%
142142
\hsection{An Example for Errors and a new Tool}%
143+
\label{sec:listExampleForErrorsAndRuff}%
143144
%
144145
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{lists_error.py}{--args format}{lists:lists_error}{%
145146
A program processing lists which exhibits some subtle errors and inefficiencies.}
@@ -190,7 +191,7 @@
190191
Each \python\ file should start with a string describing its purpose~\cite{PEP257}. %
191192
This can either be a single line, like a headline, or a longer text. %
192193
In the second case, the first line must be a headline, followed by an empty line, followed by the rest of the text. %
193-
Either way, it must be a string delimited by~\pythonil{"""..."""}\pythonIdx{\textquotedbl\textquotedbl\textquotedbl}~\cite{PEP257,PEP8}.%
194+
Either way, it must be a string delimited by~\pythonil{"""..."""}\pythonIdx{\textquotedbl\textquotedbl\textquotedbl\idxdots\textquotedbl\textquotedbl\textquotedbl}~\cite{PEP257,PEP8}.%
194195
\pythonIdx{str!doc}%
195196
}%
196197
%

text/main/basics/collections/sets/sets.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
%
5050
\begin{sloppypar}%
5151
In \cref{lst:sets:sets_1}, we provide a first example for creating and working with sets.
52-
Sets can be created by using curly braces, i.e, \pythonilIdx{\{...\}}.
52+
Sets can be created by using curly braces, i.e, \pythonil{\{...\}}\pythonIdx{\textbraceleft\idxdots\textbraceright!set}.
5353
They can be type-hinted using the notation \pythonil{set[elementType]}\pythonIdx{set!type hint} where \pythonil{elementType} is the type of elements to be stored in the set.
5454
The line \pythonil{upper: set[str] = \{"A", "G", "B", "T", "V"\}} creates the variable \pythonil{upper}, which points to a set of the five uppercase latin characters~\pythonil{"A"}, \pythonil{"G"}, \pythonil{"B"}, \pythonil{"T"}, and~\pythonil{"V"}.
5555
The type hint~\pythonil{set[str]} states that this is a set that shall contain only strings.%

text/main/basics/collections/tuples/tuples.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
While the \python\ interpreter permits us to ignore this and still store arbitrary objects in that list, this would violate the idea behind lists.
2323
Tuples, on the other hand, are designed to contain elements of different types.
2424
Since they cannot be changed, it will always be clear which element of which type is at which location.
25-
Three, tuples are defined using parentheses instead of square brackets, i.e., with~\pythonilIdx{(...)}.%
25+
Three, tuples are defined using parentheses instead of square brackets, i.e., with~\pythonil{(...)}\pythonIdx{(\idxdots)}.%
2626
%
2727
\bestPractice{listOrTuple}{%
2828
When you need to use an indexable sequence of objects, use a list if you intent to modify this sequence. %

text/main/basics/simpleDataTypesAndOperations/none/none.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
\pythonilIdx{None} is used in scenarios where we want to specify that something does not have any value.
1717
It is not an integer, float, string, or bool.
18-
\pythonilIdx{None} is not equivalent to \pythonil{0}, it is not equivalent to~\pythonilIdx{nan}, and also different from the empty string~\pythonil{""}\pythonIdx{{\textquotedbl\textquotedbl}}.
18+
\pythonilIdx{None} is not equivalent to \pythonil{0}, it is not equivalent to~\pythonilIdx{nan}, and also different from the empty string~\pythonil{""}\pythonIdx{\textquotedbl\textquotedbl}.
1919
It is just nothing.
2020

2121
\cref{fig:none} illustrates some of the things we can do with \pythonilIdx{None}.

0 commit comments

Comments
 (0)