day1/Session-2.tex
changeset 109 16e04782baac
parent 87 cd29428cd8f5
equal deleted inserted replaced
108:324b617ce8cd 109:16e04782baac
   157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   158 
   158 
   159 \section{Functions}
   159 \section{Functions}
   160 \subsection{Defining}
   160 \subsection{Defining}
   161 \begin{frame}[fragile]
   161 \begin{frame}[fragile]
   162 \frametitle{Functions: examples}
   162 \frametitle{Functions: Definition}
   163   \begin{lstlisting}
   163 \begin{itemize}
   164 def signum( r ):
   164   \item \kwrd{def} keyword
   165     """returns 0 if r is zero
   165   \item 
   166     -1 if r is negative
   166 \end{itemize}
   167     +1 if r is positive"""
       
   168     if r < 0:
       
   169         return -1
       
   170     elif r > 0:
       
   171         return 1
       
   172     else:
       
   173         return 0
       
   174   \end{lstlisting}
       
   175 \end{frame}
   167 \end{frame}
   176 
   168 
   177 \begin{frame}[fragile]
   169 \begin{frame}[fragile]
   178   \frametitle{Functions: examples}
   170   \frametitle{Functions: examples}
   179   \begin{lstlisting}
   171   \begin{lstlisting}
   180 def pad( n, size ): 
   172 In [35]: def plot_sinx():
   181     """pads integer n with spaces
   173    ....:     x = linspace(0, 2*pi, 100)
   182     into a string of length size
   174    ....:     plt.plot(x, sin(x))
   183     """
   175    ....:     plt.show()
   184     SPACE = ' '
   176    ....:    
   185     s = str( n )
   177 
   186     padSize = size - len( s )
   178 In [36]: plot_sinx()
   187     return padSize * SPACE + s
       
   188   \end{lstlisting}
   179   \end{lstlisting}
   189 \pause
   180 \pause
   190 \emphbar{What about \% formatting?}
   181 \emphbar{What about \% formatting?}
   191 \end{frame}
   182 \end{frame}
   192 
   183