Skip to content

More formatting #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
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!")

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}")
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}

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
83 changes: 83 additions & 0 deletions exceptions/slides/contents.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/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/manyerr.py}
\end{example}
\end{frame}

15 changes: 15 additions & 0 deletions exceptions/slides/examples/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 exceptions/slides/examples/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 exceptions/slides/examples/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 exceptions/slides/examples/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}")

Binary file added exceptions/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.
45 changes: 45 additions & 0 deletions exceptions/slides/notes.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
\documentclass{article}

\usepackage[hyphens]{url}
\usepackage[hidelinks]{hyperref}

\input{preamble.tex}

\usepackage[noamsthm,notheorems]{beamerarticle}
\setjobnamebeamerversion{slides}

%\usepackage{authblk}
%\let\institute\affil

\declaretheorem[numbered=unless unique,style=theorem]{theorem}
\declaretheorem[numbered=unless unique,style=definition]{definition}
\declaretheorem[numbered=unless unique,style=definition]{assumption}
\declaretheorem[numbered=unless unique,style=definition]{protocol}
\declaretheorem[numbered=unless unique,style=example]{example}
%\declaretheorem[style=definition,numbered=unless unique,
% name=Example,refname={example,examples}]{example}
\declaretheorem[numbered=unless unique,style=remark]{remark}
\declaretheorem[numbered=unless unique,style=remark]{idea}
\declaretheorem[numbered=unless unique,style=exercise]{exercise}
\declaretheorem[numbered=unless unique,style=exercise]{question}
\declaretheorem[numbered=unless unique,style=solution]{solution}

\begin{document}
\title{%
Felhantering
}
\author{Daniel Bosk}
\institute{%
KTH EECS
}

\maketitle

\begin{abstract}
\input{abstract.tex}
\end{abstract}

\input{contents.tex}

\printbibliography
\end{document}
42 changes: 42 additions & 0 deletions exceptions/slides/preamble.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[british]{babel}
\usepackage{booktabs}

\usepackage[all]{foreign}
\renewcommand{\foreignfullfont}{}
\renewcommand{\foreignabbrfont}{}

\usepackage{newclude}
\usepackage{import}

\usepackage[strict]{csquotes}
\usepackage[single]{acro}

\usepackage[natbib,style=alphabetic,maxbibnames=99]{biblatex}
\addbibresource{slides.bib}

\usepackage{subcaption}

\usepackage[noend]{algpseudocode}
\usepackage{xparse}

\let\email\texttt

\usepackage{listings}
\lstset{%
basicstyle=\footnotesize,
numbers=left
}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[unq]{unique}
\DeclareMathOperator{\powerset}{\mathcal{P}}

\usepackage[binary-units]{siunitx}

\usepackage[capitalize]{cleveref}
Loading