day2/session5.tex
changeset 288 c4e25269a86c
parent 263 8a4a1e5aec85
child 289 884d42eff66d
equal deleted inserted replaced
287:d4ad532525a2 288:c4e25269a86c
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2 %Tutorial slides on Python.
     2 % Tutorial slides on Python.
     3 %
     3 %
     4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
     4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
     5 % Copyright (c) 2005-2009, Prabhu Ramachandran
     5 % Copyright (c) 2005-2009, Prabhu Ramachandran
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     7 
     7 
     8 \documentclass[14pt,compress]{beamer}
     8 \documentclass[compress,14pt]{beamer}
     9 %\documentclass[draft]{beamer}
     9 % \documentclass[handout]{beamer}
    10 %\documentclass[compress,handout]{beamer}
    10 % \usepackage{pgfpages}
    11 %\usepackage{pgfpages} 
    11 % \pgfpagesuselayout{4 on 1}[a4paper,border, shrink=5mm,landscape]
    12 %\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
    12 \usepackage{tikz}
    13 
    13 \newcommand{\hyperlinkmovie}{}
    14 % Modified from: generic-ornate-15min-45min.de.tex
    14 %\usepackage{movie15}
       
    15 
       
    16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    17 % Note that in presentation mode 
       
    18 % \paperwidth  364.19536pt
       
    19 % \paperheight 273.14662pt
       
    20 % h/w = 0.888
       
    21 
       
    22 
    15 \mode<presentation>
    23 \mode<presentation>
    16 {
    24 {
    17   \usetheme{Warsaw}
    25   \usetheme{Warsaw}
       
    26   %\usetheme{Boadilla}
       
    27   %\usetheme{default}
    18   \useoutertheme{infolines}
    28   \useoutertheme{infolines}
    19   \setbeamercovered{transparent}
    29   \setbeamercovered{transparent}
    20 }
    30 }
    21 
    31 
       
    32 % To remove navigation symbols
       
    33 \setbeamertemplate{navigation symbols}{}
       
    34 
       
    35 \usepackage{amsmath}
    22 \usepackage[english]{babel}
    36 \usepackage[english]{babel}
    23 \usepackage[latin1]{inputenc}
    37 \usepackage[latin1]{inputenc}
    24 %\usepackage{times}
    38 \usepackage{times}
    25 \usepackage[T1]{fontenc}
    39 \usepackage[T1]{fontenc}
    26 
    40 
    27 % Taken from Fernando's slides.
    41 % Taken from Fernando's slides.
    28 \usepackage{ae,aecompl}
    42 \usepackage{ae,aecompl}
    29 \usepackage{mathpazo,courier,euler}
    43 \usepackage{mathpazo,courier,euler}
    30 \usepackage[scaled=.95]{helvet}
    44 \usepackage[scaled=.95]{helvet}
       
    45 \usepackage{pgf}
    31 
    46 
    32 \definecolor{darkgreen}{rgb}{0,0.5,0}
    47 \definecolor{darkgreen}{rgb}{0,0.5,0}
    33 
    48 
    34 \usepackage{listings}
    49 \usepackage{listings}
    35 \lstset{language=Python,
    50 \lstset{language=Python,
    38   stringstyle=\color{darkgreen},
    53   stringstyle=\color{darkgreen},
    39   showstringspaces=false,
    54   showstringspaces=false,
    40   keywordstyle=\color{blue}\bfseries}
    55   keywordstyle=\color{blue}\bfseries}
    41 
    56 
    42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    43 % Macros
    58 % My Macros
       
    59 \setbeamercolor{postit}{bg=yellow,fg=black}
    44 \setbeamercolor{emphbar}{bg=blue!20, fg=black}
    60 \setbeamercolor{emphbar}{bg=blue!20, fg=black}
    45 \newcommand{\emphbar}[1]
    61 \newcommand{\emphbar}[1]
    46 {\begin{beamercolorbox}[rounded=true]{emphbar} 
    62 {\begin{beamercolorbox}[rounded=true]{emphbar} 
    47       {#1}
    63       {#1}
    48  \end{beamercolorbox}
    64  \end{beamercolorbox}
    49 }
    65 }
       
    66 %{\centerline{\fcolorbox{gray!50} {blue!10}{
       
    67 %\begin{minipage}{0.9\linewidth}
       
    68 %    {#1} 
       
    69 %\end{minipage}
       
    70 %    }}}
       
    71 
       
    72 \newcommand{\myemph}[1]{\structure{\emph{#1}}}
       
    73 \newcommand{\PythonCode}[1]{\lstinline{#1}}
       
    74 
       
    75 \newcommand{\tvtk}{\texttt{tvtk}}
       
    76 \newcommand{\mlab}{\texttt{mlab}}
       
    77 \newcommand{\typ}[1]{\lstinline{#1}}
    50 \newcounter{time}
    78 \newcounter{time}
    51 \setcounter{time}{0}
    79 \setcounter{time}{0}
    52 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
    80 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\vspace*{0.1in}\tiny \thetime\ m}}
    53 
    81 
    54 \newcommand{\typ}[1]{\texttt{#1}}
    82 \newcommand\BackgroundPicture[1]{%
    55 
    83   \setbeamertemplate{background}{%
    56 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
    84       \parbox[c][\paperheight]{\paperwidth}{%
    57 
    85       \vfill \hfill
    58 %%% This is from Fernando's setup.
    86  \hfill \vfill
    59 % \usepackage{color}
    87 }}}
    60 % \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
    88 
    61 % % Use and configure listings package for nicely formatted code
    89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    62 % \usepackage{listings}
    90 % Configuring the theme
    63 % \lstset{
    91 %\setbeamercolor{normal text}{fg=white}
    64 %    language=Python,
    92 %\setbeamercolor{background canvas}{bg=black}
    65 %    basicstyle=\small\ttfamily,
    93 
    66 %    commentstyle=\ttfamily\color{blue},
       
    67 %    stringstyle=\ttfamily\color{orange},
       
    68 %    showstringspaces=false,
       
    69 %    breaklines=true,
       
    70 %    postbreak = \space\dots
       
    71 % }
       
    72 
    94 
    73 
    95 
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    75 % Title page
    97 % Title page
    76 \title[Exercises]{Exercises}
    98 \title[Python Development]{Python Development}
    77 
    99 
    78 \author[FOSSEE] {FOSSEE}
   100 \author[FOSSEE] {FOSSEE}
    79 
   101 
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
   102 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    81 \date[] {1 November, 2009\\Day 2, Session 4}
   103 \date[] {1 November, 2009\\Day 2, Session 3}
    82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    83 
   105 
    84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
   106 %\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo}
    85 %\logo{\pgfuseimage{iitmlogo}}
   107 %\logo{\pgfuseimage{iitblogo}}
    86 
   108 
       
   109 \AtBeginSection[]
       
   110 {
       
   111   \begin{frame}<beamer>
       
   112     \frametitle{Outline}
       
   113       \Large
       
   114     \tableofcontents[currentsection,currentsubsection]
       
   115   \end{frame}
       
   116 }
    87 
   117 
    88 %% Delete this, if you do not want the table of contents to pop up at
   118 %% Delete this, if you do not want the table of contents to pop up at
    89 %% the beginning of each subsection:
   119 %% the beginning of each subsection:
    90 \AtBeginSubsection[]
   120 \AtBeginSubsection[]
    91 {
   121 {
    93     \frametitle{Outline}
   123     \frametitle{Outline}
    94     \tableofcontents[currentsection,currentsubsection]
   124     \tableofcontents[currentsection,currentsubsection]
    95   \end{frame}
   125   \end{frame}
    96 }
   126 }
    97 
   127 
    98 
   128 \AtBeginSection[]
    99 % If you wish to uncover everything in a step-wise fashion, uncomment
   129 {
   100 % the following command: 
   130   \begin{frame}<beamer>
   101 %\beamerdefaultoverlayspecification{<+->}
   131     \frametitle{Outline}
   102 
   132     \tableofcontents[currentsection,currentsubsection]
   103 %\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
   133   \end{frame}
   104 
   134 }
   105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   106 % DOCUMENT STARTS
   136 % DOCUMENT STARTS
   107 \begin{document}
   137 \begin{document}
   108 
   138 
   109 \begin{frame}
   139 \begin{frame}
   110   \titlepage
   140   \maketitle
   111 \end{frame}
   141 \end{frame}
   112 
   142 
   113 \begin{frame}{Problem 1.1}
   143 \section{Tests: Getting started}
   114   The aliquot of a number is defined as: the sum of the \emph{proper} divisors of the number. \\For example: 
   144 \begin{frame}[fragile] 
   115 \center{aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16.}\\
   145   \frametitle{gcd revisited!}
   116   Write a function that returns the aliquot number of a given number. 
   146   \begin{itemize}
   117 \end{frame}
   147   \item Open gcd.py
   118 
   148   \end{itemize}  
   119 \begin{frame}{Problem 1.2}
   149 \begin{lstlisting}
   120   Pair of numbers (a, b) is said to be \alert{amicable} if aliquot number of a is b and aliquot number of b is a.\\
   150     def gcd(a, b):
   121   Example: \texttt{220, 284}\\
   151         if a % b == 0: 
   122   Write a program that prints all four digit amicable pairs.
   152             return b
   123   
   153         return gcd(b, a%b)
   124 \inctime{20}
   154 
   125 \end{frame}
   155     print gcd(15, 65)
   126 
   156     print gcd(16, 76)
   127 %% \begin{frame}{Problem 2}
   157 \end{lstlisting}
   128 %%   Given an empty chessboard and one Bishop placed in any s%quare, say (r, c), generate the list of all squares the Bi%shop could move to.
   158   \begin{itemize}
   129 
   159   \item python gcd.py
   130 %% \end{frame}
   160   \end{itemize}
   131 
   161 \end{frame}
   132 \begin{frame}[fragile]
   162 
   133   \frametitle{Problem Set 2}
   163 \begin{frame}[fragile] 
   134   Given a string like, ``1, 3-7, 12, 15, 18-21'', produce the list \\
   164   \frametitle{Find lcm using our gcd module}
       
   165   \begin{itemize}
       
   166   \item Open lcm.py  
       
   167   \item $lcm = \frac{a*b}{gcd(a,b)}$
       
   168   \end{itemize}  
       
   169 \begin{lstlisting}
       
   170     from gcd import gcd    
       
   171     def lcm(a, b):
       
   172         return (a * b) / gcd(a, b)
       
   173     
       
   174     print lcm(14, 56)
       
   175 \end{lstlisting}
       
   176   \begin{itemize}
       
   177   \item python lcm.py
       
   178   \end{itemize}
   135   \begin{lstlisting}
   179   \begin{lstlisting}
   136     [1,3,4,5,6,7,12,15,18,19,20,21]
   180 5
   137   \end{lstlisting}
   181 4
   138 \inctime{10}
   182 56
   139 \end{frame}
   183   \end{lstlisting}    
   140 
   184 \end{frame}
   141 \begin{frame} 
   185 
   142   \frametitle{Problem Set 3}
   186 \begin{frame}[fragile] 
   143   \begin{description}
   187   \frametitle{Writing stand-alone module}  
   144     \item[3.1] Count word frequencies in a file.
   188 Edit gcd.py file to:
   145 \end{description}
   189 \begin{lstlisting}
   146 \inctime{5}
   190     def gcd(a, b):
   147 \end{frame}
   191         if a % b == 0: 
   148 
   192             return b
   149 \begin{frame}[fragile]
   193         return gcd(b, a%b)
   150   \frametitle{Problem set 4}
   194 
   151   Central difference
   195     if __name__ == "__main__":        
   152   \begin{equation*}
   196         print gcd(15, 65)
   153   \frac{sin(x+h)-sin(x-h)}{2h}
   197         print gcd(16, 76)
   154   \end{equation*}
   198 \end{lstlisting}
       
   199   \begin{itemize}
       
   200   \item python gcd.py
       
   201   \item python lcm.py
       
   202   \end{itemize}
       
   203 \end{frame}
       
   204 
       
   205 \begin{frame}[fragile]
       
   206   \frametitle{More use of main}
       
   207   For automating tests.
   155   \begin{lstlisting}
   208   \begin{lstlisting}
   156   In []: x = linspace(0, 2*pi, 100)
   209 if __name__ == '__main__':
   157   In []: y = sin(x)
   210     for line in open('numbers.txt'):
   158   In []: deltax = x[1] - x[0]
   211         numbers = line.split()
       
   212         x = int(numbers[0])
       
   213         y = int(numbers[1])
       
   214         result = (int(numbers[2]))
       
   215         assert gcd(x, y) == result
       
   216   \end{lstlisting}  
       
   217 \end{frame}
       
   218 
       
   219 \section{Coding Style}
       
   220 \begin{frame}{Readability and Consistency}
       
   221     \begin{itemize}
       
   222         \item Readability Counts!\\Code is read more often than its written.
       
   223         \item Consistency!
       
   224         \item Know when to be inconsistent.
       
   225       \end{itemize}
       
   226 \end{frame}
       
   227 
       
   228 \begin{frame}[fragile] \frametitle{A question of good style}
       
   229   \begin{lstlisting}
       
   230     amount = 12.68
       
   231     denom = 0.05
       
   232     nCoins = round(amount/denom)
       
   233     rAmount = nCoins * denom
   159   \end{lstlisting}
   234   \end{lstlisting}
   160   \pause
   235   \pause
   161     \begin{enumerate}
   236   \begin{block}{Style Rule \#1}
   162       \item Given this, get the finite difference of sin in the range 0 to 2*pi
   237     Naming is 80\% of programming
   163     \end{enumerate}
   238   \end{block}
   164 \end{frame}
   239 \end{frame}
   165 
   240 
       
   241 \begin{frame}[fragile]
       
   242   \frametitle{Code Layout}
       
   243   \begin{itemize}
       
   244         \item Indentation
       
   245         \item Tabs or Spaces??
       
   246         \item Maximum Line Length
       
   247         \item Blank Lines
       
   248         \item Encodings
       
   249    \end{itemize}
       
   250 \end{frame}
       
   251 
       
   252 \begin{frame}{Whitespaces in Expressions}
       
   253   \begin{itemize}
       
   254         \item When to use extraneous whitespaces??
       
   255         \item When to avoid extra whitespaces??
       
   256         \item Use one statement per line
       
   257    \end{itemize}
       
   258 \end{frame}
       
   259 
       
   260 \begin{frame}{Comments}
       
   261   \begin{itemize}
       
   262         \item No comments better than contradicting comments
       
   263         \item Block comments
       
   264         \item Inline comments
       
   265    \end{itemize}
       
   266 \end{frame}
       
   267 
       
   268 \begin{frame}{Docstrings}
       
   269   \begin{itemize}
       
   270         \item When to write docstrings?
       
   271         \item Ending the docstrings
       
   272         \item One liner docstrings
       
   273    \end{itemize}
       
   274 More information at PEP8: http://www.python.org/dev/peps/pep-0008/
       
   275 \inctime{5}
       
   276 \end{frame}
       
   277 
       
   278 \section{Debugging}
       
   279 \subsection{Errors and Exceptions}
       
   280 \begin{frame}[fragile]
       
   281  \frametitle{Errors}
       
   282  \begin{lstlisting}
       
   283 In []: while True print 'Hello world'
       
   284  \end{lstlisting}
       
   285 \pause
       
   286   \begin{lstlisting}
       
   287   File "<stdin>", line 1, in ?
       
   288     while True print 'Hello world'
       
   289                    ^
       
   290 SyntaxError: invalid syntax
       
   291 \end{lstlisting}
       
   292 \end{frame}
       
   293 
       
   294 \begin{frame}[fragile]
       
   295  \frametitle{Exceptions}
       
   296  \begin{lstlisting}
       
   297 In []: print spam
       
   298 \end{lstlisting}
       
   299 \pause
       
   300 \begin{lstlisting}
       
   301 Traceback (most recent call last):
       
   302   File "<stdin>", line 1, in <module>
       
   303 NameError: name 'spam' is not defined
       
   304 \end{lstlisting}
       
   305 \end{frame}
       
   306 
       
   307 \begin{frame}[fragile]
       
   308  \frametitle{Exceptions}
       
   309  \begin{lstlisting}
       
   310 In []: 1 / 0
       
   311 \end{lstlisting}
       
   312 \pause
       
   313 \begin{lstlisting}
       
   314 Traceback (most recent call last):
       
   315   File "<stdin>", line 1, in <module>
       
   316 ZeroDivisionError: integer division 
       
   317 or modulo by zero
       
   318 \end{lstlisting}
       
   319 \end{frame}
       
   320 
       
   321 \begin{frame}[fragile]
       
   322   \frametitle{Handling Exceptions}
       
   323   Python uses \typ{try} and \typ{except} clause.
       
   324   %%Revisiting the raw\_input
       
   325   \begin{lstlisting}
       
   326 a = raw_input('Enter number(Q to quit):')
       
   327 try:
       
   328     num = int(a)
       
   329     print num
       
   330 except:
       
   331     if a == 'Q':
       
   332         print 'Exiting...'
       
   333     else:
       
   334         print 'Wrong input!'      
       
   335   \end{lstlisting}
       
   336   
       
   337   
       
   338 \end{frame}
       
   339 
       
   340 %% \begin{frame}[fragile]
       
   341 %%   \frametitle{Solving it with \typ{try} and \typ{except}}
       
   342 %% \vspace{-0.2in}
       
   343 %%   \begin{lstlisting}
       
   344 %% highest = 0
       
   345 %% for record in open('sslc1.txt'):
       
   346 %%     fields = record.split(';')
       
   347 %%     try:
       
   348 %%         total = 0
       
   349 %%         for score_str in fields[3:8]:
       
   350 %%             score = int(score_str)
       
   351 %%             total += score
       
   352 %%         if total > highest:
       
   353 %%             highest = total
       
   354 %%     except:        
       
   355 %%         pass
       
   356 %% print highest
       
   357 %%   \end{lstlisting}
       
   358 %% \end{frame}
       
   359 \subsection{Strategy}
       
   360 \begin{frame}[fragile]
       
   361     \frametitle{Debugging effectively}
       
   362     \begin{itemize}
       
   363         \item \typ{print} based strategy
       
   364         \item Process:
       
   365     \end{itemize}
       
   366 \begin{center}
       
   367 \pgfimage[interpolate=true,width=5cm,height=5cm]{DebugginDiagram.png}
       
   368 \end{center}
       
   369 \end{frame}
       
   370 
       
   371 \begin{frame}[fragile]
       
   372     \frametitle{Debugging effectively}
       
   373     \begin{itemize}
       
   374       \item Using \typ{\%debug} in IPython
       
   375     \end{itemize}
       
   376 \end{frame}
       
   377 
       
   378 \begin{frame}[fragile]
       
   379 \frametitle{Debugging in IPython}
       
   380 \small
       
   381 \begin{lstlisting}
       
   382 In []: import mymodule
       
   383 In []: mymodule.test()
       
   384 ---------------------------------------------
       
   385 NameError   Traceback (most recent call last)
       
   386 <ipython console> in <module>()
       
   387 mymodule.py in test()
       
   388       1 def test():
       
   389 ----> 2     print spam
       
   390 NameError: global name 'spam' is not defined
       
   391 
       
   392 In []: %debug
       
   393 > mymodule.py(2)test()
       
   394       0     print spam
       
   395 ipdb> 
       
   396 \end{lstlisting}
       
   397 \inctime{15} 
       
   398 \end{frame}
       
   399 
       
   400 \subsection{Exercise}
       
   401 \begin{frame}[fragile]
       
   402 \frametitle{Debugging: Exercise}
       
   403 \small
       
   404 \begin{lstlisting}
       
   405 science = {}
       
   406 
       
   407 for record in open('sslc1.txt'):
       
   408     fields = record.split(';')
       
   409     region_code = fields[0].strip()
       
   410 
       
   411     score_str = fields[6].strip()
       
   412     score = int(score_str) if score_str != 'AA' 
       
   413                            else 0
       
   414 
       
   415     if score > 90:
       
   416         science[region_code] += 1
       
   417 
       
   418 pie(science.values(), labels=science.keys())
       
   419 savefig('science.png')
       
   420 \end{lstlisting}
       
   421 \inctime{10}
       
   422 \end{frame}
       
   423 
       
   424 %% \begin{frame}
       
   425 %%     \frametitle{Testing}
       
   426    
       
   427 %%     \begin{itemize}
       
   428 %%         \item Writing tests is really simple!
       
   429 
       
   430 %%         \item Using nose.
       
   431 
       
   432 %%         \item Example!
       
   433 %%     \end{itemize}
       
   434 %% \end{frame}
       
   435 
       
   436 \section{Test Driven Approach}
   166 \begin{frame}
   437 \begin{frame}
   167   \frametitle{Problem Set 5}
   438     \frametitle{Need for Testing!}
   168   \begin{itemize}
   439    
   169       \item[5.1] Write a function that plots any regular n-gon given \typ{n}.
       
   170       \item[5.2] Consider the logistic map, $f(x) = kx(1-x)$, plot it for
       
   171           $k=2.5, 3.5$ and $4$ in the same plot.
       
   172 \end{itemize}
       
   173 \end{frame}
       
   174 
       
   175 \begin{frame}[fragile] 
       
   176 \frametitle{Problem Set 5}
       
   177   \begin{columns}
       
   178     \column{0.6\textwidth}
       
   179     \small{
       
   180     \begin{itemize}
   440     \begin{itemize}
   181       \item[3] Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) = kx(1-x)$.  Plot the successive iterates of this process as explained below. 
   441         \item Quality
   182     \end{itemize}}
   442         \item Regression
   183     \column{0.35\textwidth}
   443         \item Documentation
   184     \hspace*{-0.5in}
   444     \end{itemize}
   185   \includegraphics[height=1.6in, interpolate=true]{data/cobweb}  
   445     %% \vspace*{0.25in}
   186 \end{columns}
   446     %% \emphbar{It is to assure that section of code is working as it is supposed to work}
   187 \end{frame}
   447 \end{frame}
       
   448 
       
   449 \begin{frame}[fragile]
       
   450     \frametitle{Example}
       
   451     \begin{block}{Problem Statement}
       
   452       Write a function to check whether a given input
       
   453       string is a palindrome.
       
   454     \end{block}
       
   455 \end{frame}
       
   456 
       
   457 \begin{frame}[fragile]
       
   458     \frametitle{Function: palindrome.py}
       
   459 \begin{lstlisting}    
       
   460 def is_palindrome(input_str):
       
   461   return input_str == input_str[::-1]
       
   462 \end{lstlisting}    
       
   463 \end{frame}
       
   464 
       
   465 \begin{frame}[fragile]
       
   466     \frametitle{Test for the palindrome: palindrome.py}
       
   467 \begin{lstlisting}    
       
   468 def test_function_normal_words():
       
   469   input = "noon"
       
   470   assert is_palindrome(input) == True
       
   471 
       
   472 if __name__ == "main'':
       
   473   test_function_normal_words()
       
   474 \end{lstlisting}    
       
   475 \end{frame}
       
   476 
       
   477 \begin{frame}[fragile]
       
   478     \frametitle{Running the tests.}
       
   479 \begin{lstlisting}    
       
   480 $ nosetests palindrome.py 
       
   481 .
       
   482 ----------------------------------------------
       
   483 Ran 1 test in 0.001s
       
   484 
       
   485 OK
       
   486 \end{lstlisting}    
       
   487 \end{frame}
       
   488 
       
   489 \begin{frame}[fragile]
       
   490     \frametitle{Exercise: Including new tests.}
       
   491 \begin{lstlisting}    
       
   492 def test_function_ignore_cases_words():
       
   493   input = "Noon"
       
   494   assert is_palindrome(input) == True
       
   495 \end{lstlisting}
       
   496      \vspace*{0.25in}
       
   497      Check\\
       
   498      \PythonCode{$ nosetests palindrome.py} \\
       
   499      \begin{block}{Task}
       
   500      Tweak the code to pass this test.
       
   501      \end{block}
       
   502 \end{frame}
       
   503 
       
   504 %\begin{frame}[fragile]
       
   505 %    \frametitle{Lets write some test!}
       
   506 %\begin{lstlisting}    
       
   507 %#for form of equation y=mx+c
       
   508 %#given m and c for two equation,
       
   509 %#finding the intersection point.
       
   510 %def intersect(m1,c1,m2,c2):
       
   511 %    x = (c2-c1)/(m1-m2)
       
   512 %    y = m1*x+c1
       
   513 %    return (x,y)
       
   514 %\end{lstlisting}
       
   515 %
       
   516 %Create a simple test for this
       
   517 %
       
   518 %function which will make it fail.
       
   519 %
       
   520 %\inctime{15} 
       
   521 %\end{frame}
       
   522 %
       
   523 
       
   524 %% \begin{frame}[fragile]
       
   525 %%     \frametitle{Exercise}
       
   526 %%     Based on Euclid's algorithm:
       
   527 %%     \begin{center}
       
   528 %%     $gcd(a,b)=gcd(b,b\%a)$
       
   529 %%     \end{center}
       
   530 %%     gcd function can be written as:
       
   531 %%     \begin{lstlisting}
       
   532 %%     def gcd(a, b):
       
   533 %%       if a%b == 0: return b
       
   534 %%       return gcd(b, a%b)
       
   535 %%     \end{lstlisting}
       
   536 %%     \vspace*{-0.15in}
       
   537 %%     \begin{block}{Task}
       
   538 %%       \begin{itemize}
       
   539 %%       \item Write at least 
       
   540 %%         two tests for above mentioned function.
       
   541 %%       \item Write a non recursive implementation
       
   542 %%       of gcd(), and test it using already 
       
   543 %%       written tests.
       
   544 %%       \end{itemize}
       
   545 %%     \end{block}
       
   546     
       
   547 %% \inctime{15} 
       
   548 %% \end{frame}
   188 
   549 
   189 \begin{frame}
   550 \begin{frame}
   190   \frametitle{Problem Set 5.3}
   551   \frametitle{Summary}
   191   Plot the cobweb plot as follows:
   552 We have coverd:
   192   \begin{enumerate}
   553   \begin{itemize}
   193     \item Start at $(x_0, 0)$ ($\implies$ i=0)
   554   \item Following and Resolving Error Messages.
   194     \item Draw a line to $(x_i, f(x_i))$
   555   \item Exceptions.
   195     \item Set $x_{i+1} = f(x_i)$
   556   \item Handling exceptions
   196     \item Draw a line to $(x_{i+1}, x_{i+1})$
   557   \item Approach for Debugging.
   197     \item $(i\implies i+1)$ 
   558   \item Writting and running tests.
   198     \item Repeat from 2 for as long as you want 
   559   \end{itemize}
   199   \end{enumerate}
       
   200 \inctime{20}
       
   201 \end{frame}
   560 \end{frame}
   202 
   561 
   203 \end{document}
   562 \end{document}