Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Vi har följande moduler:
- `overview`
- `variables`
- `conditionals`
- `exceptions`
- `containers`
- `functions`
- `files`
Expand Down
5 changes: 4 additions & 1 deletion conditionals/slides/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: notes.pdf slides.pdf
all: notes.pdf slides.pdf slides-more.pdf

SRC+= preamble.tex
SRC+= abstract.tex contents.tex
Expand All @@ -10,6 +10,9 @@ notes.pdf: ${SRC}
slides.pdf: slides.tex
slides.pdf: ${SRC}

slides-more.pdf: preamble.tex abstract.tex more.tex figs/docs-strings.png
slides-more.pdf: ../../exceptions/slides/contents.tex


.PHONY: clean
clean:
Expand Down
8 changes: 8 additions & 0 deletions conditionals/slides/examples-more/align-binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
n = 10

while n > 0:
print(f"n = {n:4b}")
n -= 1

print("Done!")

9 changes: 9 additions & 0 deletions conditionals/slides/examples-more/align-exp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
n = "10"
"""
4.4f som format specification: den första fyran anger den *totala* bredden,
inklusive decimalerna. Därav hade den ingen effekt i vårt exempel, då vi hade
fyra decimaler och lite till. Om vi hade satt den till 10, skulle vi ha sett
effekt.
"""
print(f"n = {float(n):4.4f}")

8 changes: 8 additions & 0 deletions conditionals/slides/examples-more/align.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
n = 10

while n > 0:
print(f"n = {n:2d}")
n -= 1

print("Done!")

3 changes: 3 additions & 0 deletions conditionals/slides/examples-more/formatpi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import math

print(f"Pi is approximately {math.pi:.3f}")
9 changes: 9 additions & 0 deletions conditionals/slides/examples-more/in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
while True:
try:
x = float(input("Mata in ett tal: "))
except ValueError as err:
print(f"Tyvärr, det blev fel: {err}, försök igen.")
else:
break

print(x)
15 changes: 15 additions & 0 deletions conditionals/slides/examples-more/manyerr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
while True:
try:
x = int(input("Nominator x = "))
y = int(input("Demoninator y = "))
print(f"{x} / {y} = {x/y}")
except ZeroDivisionError:
print("Sorry, the denominator must be non-zero.")
continue
except ValueError:
print("Sorry, you must enter numbers.")
continue
except Exception as err:
print(f"Sorry, an unexpected error occured: {err}")
break

5 changes: 5 additions & 0 deletions conditionals/slides/examples-more/nameerr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
prynt("3")
except Exception as err:
print(f"We caught this: {err}")

5 changes: 5 additions & 0 deletions conditionals/slides/examples-more/valuerr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
int("a")
except Exception as err:
print(f"We caught this: {err}")

5 changes: 5 additions & 0 deletions conditionals/slides/examples-more/zerodiv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
try:
5/0
except Exception as err:
print(f"We caught this: {err}")

83 changes: 83 additions & 0 deletions conditionals/slides/exceptions.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
\mode*

\section{Fel och felhantering}

\subsection{Särfall}

\begin{frame}[fragile]
\begin{example}
\begin{lstlisting}
>>> int("a")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'a'
>>>
\end{lstlisting}
\end{example}
\end{frame}

\begin{frame}[fragile]
\begin{example}
\begin{lstlisting}
>>> 5/0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
>>>
\end{lstlisting}
\end{example}
\end{frame}

\begin{frame}[fragile]
\begin{example}
\begin{lstlisting}
>>> prynt(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'prynt' is not defined
>>>
\end{lstlisting}
\end{example}
\end{frame}

\subsection{Felhantering: att fånga särfall}

\begin{frame}
\includegraphics[width=\columnwidth]{figs/docs-except.png}
\end{frame}

\begin{frame}[fragile]
\begin{example}[Fånga särfall: valuerr.py]
\lstinputlisting{examples-more/valuerr.py}
\end{example}

\pause

\begin{example}
\begin{lstlisting}[language={}]
$ python3 valuerr.py
We caught this: invalid literal for int() with base 10: 'a'
\end{lstlisting}
\end{example}
\end{frame}

\begin{frame}[fragile]
\begin{lstlisting}
try:
# error
except Exception as err:
print("Catch all errors!")
\end{lstlisting}
\begin{remark}
\begin{itemize}
\item \lstinline{except Exception as err} fångar \emph{allt}!
\end{itemize}
\end{remark}
\end{frame}

\begin{frame}[fragile]
\begin{example}[manyerr.py]
\lstinputlisting{examples-more/manyerr.py}
\end{example}
\end{frame}

Binary file added conditionals/slides/figs/docs-except.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added conditionals/slides/figs/docs-strings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions conditionals/slides/more.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
\mode*

\section{Formattera strängar}

\subsection{Dokumentation}

\begin{frame}
\includegraphics[width=\columnwidth]{figs/docs-strings.png}
\end{frame}


\subsection{Några fler saker man kan göra}

\begin{frame}
\begin{example}[formatpi.py]
\lstinputlisting{examples-more/formatpi.py}
\end{example}
\end{frame}

\begin{frame}
\begin{example}[align.py]
\lstinputlisting{examples-more/align.py}
\end{example}
\end{frame}

\begin{frame}
\begin{example}[align-binary.py]
\lstinputlisting{examples-more/align-binary.py}
\end{example}
\end{frame}

116 changes: 116 additions & 0 deletions conditionals/slides/slides-more.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
\documentclass[ignoreframetext]{beamer}
\input{preamble.tex}
\usepackage{import}

\usetheme{Berlin}
\setbeamertemplate{footline}%{miniframes theme}
{%
\begin{beamercolorbox}[colsep=1.5pt]{upper separation line foot}
\end{beamercolorbox}
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{author in head/foot}%
\leavevmode{\usebeamerfont{author in head/foot}\insertshortauthor}%
\hfill%
{\usebeamerfont{institute in head/foot}\usebeamercolor[fg]{institute in head/foot}\insertshortinstitute}%
\end{beamercolorbox}%
\begin{beamercolorbox}[ht=2.5ex,dp=1.125ex,%
leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
{\usebeamerfont{title in head/foot}\insertshorttitle} \hfill \insertframenumber%
\end{beamercolorbox}%
\begin{beamercolorbox}[colsep=1.5pt]{lower separation line foot}
\end{beamercolorbox}
}
\setbeamercovered{transparent}
\setbeamertemplate{bibliography item}[text]

\AtBeginSection[]{%
\begin{frame}<beamer>
\tableofcontents[currentsection]
\end{frame}
}

\ProvideDocumentEnvironment{assumption}{o}{%
\IfValueTF{#1}{%
\begin{block}{Assumption: #1}
}{%
\begin{block}{Assumption}
}
}{%
\end{block}
}

\ProvideDocumentEnvironment{protocol}{o}{%
\IfValueTF{#1}{%
\begin{block}{Protocol: #1}
}{%
\begin{block}{Protocol}
}
}{%
\end{block}
}

\ProvideDocumentEnvironment{remark}{o}{%
\IfValueTF{#1}{%
\begin{alertblock}{Note: #1}
}{%
\begin{alertblock}{Note}
}
}{%
\end{alertblock}
}

\ProvideDocumentEnvironment{idea}{o}{%
\IfValueTF{#1}{%
\begin{block}{Idea: #1}
}{%
\begin{block}{Idea}
}
}{%
\end{block}
}

\ProvideDocumentEnvironment{question}{o}{%
\setbeamercolor{block body}{bg=orange!15,fg=black}
\setbeamercolor{block title}{bg=orange,fg=white}
\setbeamercolor{local structure}{fg=orange}
\IfValueTF{#1}{%
\begin{block}{Question: #1}
}{%
\begin{block}{Question}
}
}{%
\end{block}
}

\ProvideDocumentEnvironment{exercise}{o}{%
\setbeamercolor{block body}{bg=yellow!10,fg=black}
\setbeamercolor{block title}{bg=yellow,fg=black}
\setbeamercolor{local structure}{fg=yellow}
\IfValueTF{#1}{%
\begin{block}{Exercise: #1}
}{%
\begin{block}{Exercise}
}
}{%
\end{block}
}


\begin{document}
\title{Mer formatering och felhantering}
\author{Daniel Bosk}
\institute{KTH EECS}

\maketitle

\mode<all>
\input{more.tex}
\mode*
\mode<all>
\input{exceptions.tex}
\mode*

\begin{frame}[allowframebreaks]
\printbibliography
\end{frame}
\end{document}
2 changes: 2 additions & 0 deletions exceptions/slides/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
notes.pdf
slides.pdf
20 changes: 20 additions & 0 deletions exceptions/slides/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: all
all: notes.pdf slides.pdf

SRC+= preamble.tex
SRC+= abstract.tex contents.tex

notes.pdf: notes.tex
notes.pdf: ${SRC}

slides.pdf: slides.tex
slides.pdf: ${SRC}


.PHONY: clean
clean:
${RM} notes.pdf slides.pdf


INCLUDE_MAKEFILES=../../makefiles
include ${INCLUDE_MAKEFILES}/tex.mk
22 changes: 22 additions & 0 deletions exceptions/slides/abstract.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
% What's the problem?
% Why is it a problem? Research gap left by other approaches?
% Why is it important? Why care?
% What's the approach? How to solve the problem?
% What's the findings? How was it evaluated, what are the results, limitations,
% what remains to be done?

% XXX Summary
\emph{Summary:}
\dots

% XXX Motivation and intended learning outcomes
\emph{Intended learning outcomes:}
\dots

% XXX Prerequisites
\emph{Prerequisites:}
\dots

% XXX Reading material
\emph{Reading:}
\dots
Loading