From 6d2794738cc160fef3baa8856fd735aa347fe9fc Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Fri, 4 Mar 2016 10:49:41 +0100 Subject: [PATCH] conditional --- Makefile | 5 +++-- p.tex | 61 +++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 9f55cf5..798a4ca 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DOCUMENT:=p all: $(DOCUMENT).pdf -%.pdf: %.tex %.fmt +%.pdf: %.tex %.fmt $(LATEX) -shell-escape $(basename $@) $(LATEX) -shell-escape $(basename $@) @@ -14,4 +14,5 @@ all: $(DOCUMENT).pdf $(LATEX) -ini -shell-escape -jobname="$(basename $@)" "&$(LATEX) $<\dump" clean: - $(RM) -v $(addprefix $(DOCUMENT)., aux fmt log nav out pdf snm toc vrb) + $(RM) -rv $(addprefix $(DOCUMENT)., aux fmt log nav out pdf snm toc vrb)\ + _minted-p diff --git a/p.tex b/p.tex index b338e76..cce1750 100644 --- a/p.tex +++ b/p.tex @@ -22,7 +22,7 @@ \begin{frame}[fragile] \frametitle{How to start} \framesubtitle{Interpreter} - \begin{minted}[breaklines]{pycon} + \begin{minted}[breaklines=true]{pycon} Python 3.5.1 (default, Dec 7 2015, 12:58:09) [GCC 5.2.0] on linux Type "help", "copyright", "credits" or "license" for more @@ -52,16 +52,21 @@ print(str(i/46) + ' hoi') \begin{frame}[fragile] \frametitle{Basictypes} \begin{block}{types} - \begin{itemize} - \item \mint{python}|int| - \item \mint{python}|float| - \item \mint{python}|str| - \item \mint{python}|list| - \end{itemize} + \begin{tabular}{ll} + \mintinline{python}{bool} & \mintinline{python}{True, False}\\ + \mintinline{python}{int} & \mintinline{python}{1, -4, 999}\\ + \mintinline{python}{complex} & \mintinline{python}{4j+1, j}\\ + \mintinline{python}{float} & \mintinline{python} + {1.0, 4.5, 5e9, float('NaN'), float('inf')}\\ + \mintinline{python}{str} & \mintinline{python} + {'hi', "hi", '"', "'", """hi"""}\\ + \mintinline{python}{list} & \mintinline{python} + {[], ..., [1, 2, 3], ['a', 42], [[], [1]]} + \end{tabular} \end{block} \begin{block}{operators} \begin{itemize} - \item Numbers: \mintinline{python}{+ - / * // \% @ **} + \item Numbers: \mintinline{python}{+ - / * // % @ **} \item Comparison: \mintinline{python}{< <= > >= == != is} \item Boolean: \mintinline{python}{and or not} \item Bitwise: \mintinline{python}{& | ^ ~ << >>} @@ -72,10 +77,48 @@ print(str(i/46) + ' hoi') \end{frame} \section{Control flow} +\subsection{If, then, else} +\begin{frame}[fragile] + \frametitle{Conditional execution} + \framesubtitle{\texttt{fizzbuzz.py}} + \begin{minted}{python} +#!/usr/bin/env python3 + +i = int(input('Enter a number: ')) +if i % 3 == 0 and i % 5 == 0: + print('fizzbuzz') +elif i % 3 == 0: + print('buzz') +elif i % 5 == 0: + print('fizz') +else: + print(i) + \end{minted} +\end{frame} + \begin{frame}[fragile] - \frametitle{} + \frametitle{Conditional execution 2} + \framesubtitle{\texttt{fizzbuzz.py}} + \begin{minted}{shell-session} +frobnicator@frobmachine~$ python fizzbuzz.py +Enter a number: 42 +buzz +frobnicator@frobmachine~$ python fizzbuzz.py +Enter a number: 15 +fizzbuzz +frobnicator@frobmachine~$ python fizzbuzz.py +Enter a number: 43 +43 +frobnicator@frobmachine~$ python fizzbuzz.py +Enter a number: 9 +fizz + \end{minted} \end{frame} +\subsection{While, for} + +\subsection{Functions} + \section{Datastructures} \section{Input/Output} -- 2.20.1