|
7 | 7 | %
|
8 | 8 | \hsection{Comparisons}%
|
9 | 9 | %
|
10 |
| -\begin{figure}% |
11 |
| -\centering% |
12 |
| -\includegraphics[width=0.8\linewidth]{\currentDir/boolComparisons}% |
13 |
| -\caption{The results of basic comparisons are instances of \pythonilIdx{bool}.}% |
14 |
| -\label{fig:boolComparisons}% |
15 |
| -\end{figure}% |
| 10 | +\gitEvalPython{bool_comparisons}{}{simple_datatypes/bool_comparisons.py}% |
| 11 | +\listingBox{exec:bool_comparisons}{The results of basic comparisons are instances of \pythonilIdx{bool}.}{,style=python_console_style}% |
16 | 12 | %
|
17 | 13 | In the sections on \pythonils{float}\pythonIdx{float} and \pythonils{int}\pythonIdx{int}, we learned how to do arithmetics with real and integer numbers.
|
18 | 14 | You have learned these operations already in preschool.
|
|
31 | 27 | %
|
32 | 28 | \end{itemize}%
|
33 | 29 | %
|
34 |
| -How to use these operators is illustrated in \cref{fig:boolComparisons}. |
| 30 | +How to use these operators is illustrated in \cref{exec:bool_comparisons}. |
35 | 31 | It shows that \pythonil{6 == 6}\pythonIdx{==} yields \pythonilIdx{True}, while \pythonil{6 != 6}\pythonIdx{"!=} yields \pythonilIdx{False}.
|
36 | 32 | The expression \pythonil{6 > 6}\pythonIdx{>} gives us \pythonilIdx{False}, but \pythonil{6 >= 6}\pythonIdx{>=} is \pythonilIdx{True}.
|
37 | 33 | \pythonil{6 < 6}\pythonIdx{<} is also \pythonilIdx{False} while \pythonil{6 <= 6} is, of course, \pythonilIdx{True}.
|
|
122 | 118 | }%
|
123 | 119 | %
|
124 | 120 | \caption{The truth tables for the Boolean operators \pythonilIdx{and}, \pythonilIdx{or}, and \pythonilIdx{not}.}%
|
125 |
| -\label{fig:boolLogicTables}% |
| 121 | +\label{exec:bool_logicTables}% |
126 | 122 | \end{figure}%
|
127 | 123 | %
|
128 |
| -\begin{figure}% |
129 |
| -\centering% |
130 |
| -\includegraphics[width=0.8\linewidth]{\currentDir/boolLogic}% |
131 |
| -\caption{The \pythonilIdx{bool} values can be combined with the Boolean logical operators \pythonilIdx{and}, \pythonilIdx{or}, and \pythonilIdx{not}.}% |
132 |
| -\label{fig:boolLogic}% |
133 |
| -\end{figure}% |
| 124 | +\gitEvalPython{bool_logic}{}{simple_datatypes/bool_logic.py}% |
| 125 | +\listingBox{exec:bool_logic}{The \pythonilIdx{bool} values can be combined with the Boolean logical operators \pythonilIdx{and}, \pythonilIdx{or}, and \pythonilIdx{not}.}{,style=python_console_style}% |
134 | 126 | %
|
135 | 127 | The most common operations with Boolean values are the well-known Boolean logical operators \pythonilIdx{and}, \pythonilIdx{or}, and \pythonilIdx{not}.
|
136 |
| -Their truth tables are illustrated in \cref{fig:boolLogicTables}.% |
| 128 | +Their truth tables are illustrated in \cref{exec:bool_logicTables}.% |
137 | 129 | %
|
138 | 130 | \begin{itemize}%
|
139 | 131 | %
|
|
147 | 139 | \end{itemize}%
|
148 | 140 | %
|
149 | 141 | \begin{sloppypar}%
|
150 |
| -In \cref{fig:boolLogic} we explore these three operators in the \python\ console. |
| 142 | +In \cref{exec:bool_logic} we explore these three operators in the \python\ console. |
151 | 143 | You can see that the operations can be used exactly as in the truth tables and yield the expected results.
|
152 | 144 | Additionally, you can of course nest and combine Boolean operators using parentheses\pythonIdx{(}\pythonIdx{)}.
|
153 | 145 | For example, \pythonil{(True or False) and ((False or True) or (False and False))} resolves to \pythonil{True and (True or False)}, which becomes \pythonil{True and True}, which ultimately becomes \pythonilIdx{True}.
|
|
0 commit comments