From: Mart Lubbers Date: Fri, 4 Mar 2016 10:16:36 +0000 (+0100) Subject: added looping X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=dd22797023bae672892eb2b53894b3c51c3da3ba;p=linuxnijmegen-python.git added looping --- diff --git a/p.tex b/p.tex index cce1750..c05b10e 100644 --- a/p.tex +++ b/p.tex @@ -116,8 +116,58 @@ fizz \end{frame} \subsection{While, for} +\begin{frame}[fragile] + \frametitle{Looping} + \begin{minted}{python} +ls = ["hello", "world", "!"] + +# Pythonic for loop +for item in ls: + print(ls) + +# C style for loop +for i in range(0, len(ls)): + print(ls[i]) + +# While loop +i = 10 +while i >= 0: + print(i); +print('fire!') + \end{minted} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Looping: Escape rope} + \begin{minted}{python} +# 100.000st prime, 100.001st prime, and a pseudoprime +numbers = [1299709, 1299721, 1299709*1299721] +for n in numbers: + for x in range(2, n): + if n % x == 0: + print(n, 'equals', x, '*', n//x) + break + else: + print(n, 'is a prime number') + +# 1299709 is a prime number +# 1299721 is a prime number +# 1689259081189 equals 1299709 * 1299721 + +# pass, continue + \end{minted} +\end{frame} \subsection{Functions} +\begin{frame}[fragile] + \frametitle{Functions} + +\end{frame} + +\begin{frame}[fragile] + \frametitle{Functions: Advanced arguments} + +\end{frame} \section{Datastructures}