Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
satyarth committed Mar 7, 2015
2 parents 4d93658 + 1ddb70a commit 4613e64
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions tex/python-workshop-2.tex
Original file line number Diff line number Diff line change
Expand Up @@ -485,32 +485,24 @@
\end{frame}

\begin{frame}[fragile]
\frametitle{More keywords: continue, pass}
\begin{itemize}
\item \lstinline|pass| is just a piece of code to say do nothing.
\item When we only have a \lstinline|if| block,
\begin{lstlisting}[xleftmargin=\dimexpr-\leftmargini]
if (cond):
print(x)
\end{lstlisting}
\item it is equivalent to the following

\begin{lstlisting}[xleftmargin=\dimexpr-\leftmargini]
if (cond):
print(x)
else:
pass
\end{lstlisting}
\pause
\item \lstinline|continue| is a way of going to the next iteration of the loop
\begin{lstlisting}[xleftmargin=\dimexpr-\leftmargini]
for num in range(10):
if (num == 5):
continue
print(num)
\end{lstlisting}
\item This prints all number except 5. If we had used \lstinline|pass| instead, then we would have printed 5 as well. Can you see why?
\end{itemize}
\frametitle{Continue}
\begin{lstlisting}
story = """
John brought 3 apples and Jenny brought
26 pears. Meanwhile, Bastian brought 22
guavas!
"""

number_of_fruits = 0

for word in story.split():
try:
number_of_fruits += int(word)
except ValueError:
continue

print(number_of_fruits, "lovely fruits!")
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
Expand Down

0 comments on commit 4613e64

Please sign in to comment.