From 64b0ff920ea3248d467c5eb082a213204c2d01c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mo=C5=BEina?= Date: Tue, 19 Jun 2018 20:52:28 +0200 Subject: Representation of rules. --- aied2018/presentation/motivation.tex | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'aied2018/presentation/motivation.tex') diff --git a/aied2018/presentation/motivation.tex b/aied2018/presentation/motivation.tex index 785bd6e..69db435 100644 --- a/aied2018/presentation/motivation.tex +++ b/aied2018/presentation/motivation.tex @@ -1,12 +1,13 @@ - What is wrong with the following program that prints all divisors? + What is wrong with the following Python program that prints all divisors? \begin{columns} \begin{column}{0.50\textwidth} \begin{Verbatim} - \textbf{def} divisors(n): - \textbf{for} d \textbf{in} range(1, \red{n}): - \textbf{if} n % d == 0: - \textbf{print}(d) -\end{Verbatim} +\textbf{def} divisors(n): + \textbf{for} d \textbf{in} range(1, \red{n}): + \textbf{if} n % d == 0: + \textbf{print}(d) +\end{Verbatim} + \end{column} \begin{column} {0.50\textwidth} Answer: \texttt{range(1,n)} generates values up to \texttt{n-1}, so \texttt{n} is not printed. Instead, \texttt{range(1,n+1)} is better. -- cgit v1.2.1