diff options
author | Puneeth Chaganti | 2010-12-10 00:04:59 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2010-12-10 00:04:59 +0530 |
commit | 4e9dbb2c03efb56544147c5c239f5f56bd3d76be (patch) | |
tree | 427a5401f928173ce9fc9dffb97851b77bd28165 /day2 | |
parent | 440b467cd3caa0a1ae6abc564d8588e9767f7b0f (diff) | |
download | workshops-4e9dbb2c03efb56544147c5c239f5f56bd3d76be.tar.gz workshops-4e9dbb2c03efb56544147c5c239f5f56bd3d76be.tar.bz2 workshops-4e9dbb2c03efb56544147c5c239f5f56bd3d76be.zip |
Fixed day2/session3.tex.
--HG--
branch : scipyin2010
Diffstat (limited to 'day2')
-rw-r--r-- | day2/session3.tex | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/day2/session3.tex b/day2/session3.tex index 1714b71..ad5c249 100644 --- a/day2/session3.tex +++ b/day2/session3.tex @@ -78,7 +78,7 @@ \author[FOSSEE Team] {The FOSSEE Group} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {1 May, 2010\\Day 2, Session 3} +\date[] {SciPy.in 2010, Tutorials} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -124,6 +124,75 @@ \end{frame} \section{Functions} + +\begin{frame}[fragile] + \frametitle{Functions} + \begin{itemize} + \item \kwrd{def} - keyword to define a function + \item Arguments are local to a function + \item Functions can return multiple values + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Functions: example} + \begin{lstlisting} +def signum( r ): + """returns 0 if r is zero + -1 if r is negative + +1 if r is positive""" + if r < 0: + return -1 + elif r > 0: + return 1 + else: + return 0 + \end{lstlisting} + \emphbar{Note docstrings} +\end{frame} + +\begin{frame}[fragile] + \frametitle {What does this function do?} + \begin{lstlisting} +def what( n ): + if n < 0: n = -n + while n > 0: + if n % 2 == 1: + return False + n /= 10 + return True + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] + {What does this function do?} +\begin{lstlisting} +def what( n ): + i = 1 + while i * i < n: + i += 1 + return i * i == n, i + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] + \frametitle {What does this function do?} + \begin{lstlisting} +def what( x, n ): + if n < 0: + n = -n + x = 1.0 / x + + z = 1.0 + while n > 0: + if n % 2 == 1: + z *= x + x *= x + n /= 2 + return z + \end{lstlisting} +\end{frame} + \subsection{Default arguments} \begin{frame}[fragile] \frametitle{Functions: default arguments} |