day2/session4.tex
changeset 298 df494695e061
parent 289 884d42eff66d
child 330 46533051b9d3
--- a/day2/session4.tex	Tue Nov 10 12:21:29 2009 +0530
+++ b/day2/session4.tex	Tue Nov 10 16:26:47 2009 +0530
@@ -144,7 +144,7 @@
 \begin{frame}[fragile] 
   \frametitle{gcd revisited!}
   \begin{itemize}
-  \item Open gcd.py
+  \item Open \texttt{gcd.py}
   \end{itemize}  
 \begin{lstlisting}
     def gcd(a, b):
@@ -156,15 +156,15 @@
     print gcd(16, 76)
 \end{lstlisting}
   \begin{itemize}
-  \item python gcd.py
+  \item \texttt{python gcd.py}
   \end{itemize}
 \end{frame}
 
 \begin{frame}[fragile] 
   \frametitle{Find lcm using our gcd module}
   \begin{itemize}
-  \item Open lcm.py  
-  \item $lcm = \frac{a*b}{gcd(a,b)}$
+  \item Open \texttt{lcm.py}  
+  \item $lcm = \frac{a * b}{gcd(a,b)}$
   \end{itemize}  
 \begin{lstlisting}
     from gcd import gcd    
@@ -174,7 +174,7 @@
     print lcm(14, 56)
 \end{lstlisting}
   \begin{itemize}
-  \item python lcm.py
+  \item \texttt{python lcm.py}
   \end{itemize}
   \begin{lstlisting}
 5
@@ -185,7 +185,7 @@
 
 \begin{frame}[fragile] 
   \frametitle{Writing stand-alone module}  
-Edit gcd.py file to:
+Edit \texttt{gcd.py} file to:
 \begin{lstlisting}
     def gcd(a, b):
         if a % b == 0: 
@@ -197,22 +197,23 @@
         print gcd(16, 76)
 \end{lstlisting}
   \begin{itemize}
-  \item python gcd.py
-  \item python lcm.py
+  \item \texttt{python gcd.py}
+  \item \texttt{python lcm.py}
   \end{itemize}
 \end{frame}
 
 \begin{frame}[fragile]
-  \frametitle{More use of main}
-  For automating tests.
+  \frametitle{Automating tests}
   \begin{lstlisting}
 if __name__ == '__main__':
     for line in open('numbers.txt'):
         numbers = line.split()
         x = int(numbers[0])
         y = int(numbers[1])
-        result = (int(numbers[2]))
-        assert gcd(x, y) == result
+        result = int(numbers[2])
+        if gcd(x, y) != result:
+            print "Failed gcd test
+                          for", x, y
   \end{lstlisting}  
 \end{frame}
 
@@ -242,7 +243,7 @@
   \frametitle{Code Layout}
   \begin{itemize}
         \item Indentation
-        \item Tabs or Spaces??
+        \item Tabs or Spaces?
         \item Maximum Line Length
         \item Blank Lines
         \item Encodings
@@ -251,8 +252,8 @@
 
 \begin{frame}{Whitespaces in Expressions}
   \begin{itemize}
-        \item When to use extraneous whitespaces??
-        \item When to avoid extra whitespaces??
+        \item When to use extraneous whitespaces?
+        \item When to avoid extra whitespaces?
         \item Use one statement per line
    \end{itemize}
 \end{frame}
@@ -319,43 +320,36 @@
 \end{frame}
 
 \begin{frame}[fragile]
+  \frametitle{Processing user input}
+  \begin{lstlisting}
+prompt = 'Enter a number(Q to quit): '
+
+a = raw_input(prompt)
+
+num = int(a) if a != 'Q' else 0
+  \end{lstlisting}
+  \emphbar{What if the user enters some other alphabet?}
+\end{frame}
+
+
+\begin{frame}[fragile]
   \frametitle{Handling Exceptions}
-  Python uses \typ{try} and \typ{except} clause.
-  %%Revisiting the raw\_input
+  Python provides \typ{try} and \typ{except} clause.
   \begin{lstlisting}
-a = raw_input('Enter number(Q to quit):')
+prompt = 'Enter a number(Q to quit): '
+
+a = raw_input(prompt)
 try:
     num = int(a)
     print num
 except:
     if a == 'Q':
-        print 'Exiting...'
+        print "Exiting ..."
     else:
-        print 'Wrong input!'      
-  \end{lstlisting}
-  
-  
+        print "Wrong input ..."
+  \end{lstlisting}  
 \end{frame}
 
-%% \begin{frame}[fragile]
-%%   \frametitle{Solving it with \typ{try} and \typ{except}}
-%% \vspace{-0.2in}
-%%   \begin{lstlisting}
-%% highest = 0
-%% for record in open('sslc1.txt'):
-%%     fields = record.split(';')
-%%     try:
-%%         total = 0
-%%         for score_str in fields[3:8]:
-%%             score = int(score_str)
-%%             total += score
-%%         if total > highest:
-%%             highest = total
-%%     except:        
-%%         pass
-%% print highest
-%%   \end{lstlisting}
-%% \end{frame}
 \subsection{Strategy}
 \begin{frame}[fragile]
     \frametitle{Debugging effectively}
@@ -421,6 +415,20 @@
 \inctime{10}
 \end{frame}
 
+\begin{frame}
+  \frametitle{Summary}
+We have covered:
+  \begin{itemize}
+  \item Following and Resolving Error Messages.
+  \item Exceptions.
+  \item Handling exceptions
+  \item Approach for Debugging.
+%  \item Writting and running tests.
+  \end{itemize}
+\end{frame}
+
+\end{document}
+
 %% \begin{frame}
 %%     \frametitle{Testing}
    
@@ -433,130 +441,116 @@
 %%     \end{itemize}
 %% \end{frame}
 
-\section{Test Driven Approach}
-\begin{frame}
-    \frametitle{Need for Testing!}
-   
-    \begin{itemize}
-        \item Quality
-        \item Regression
-        \item Documentation
-    \end{itemize}
-    %% \vspace*{0.25in}
-    %% \emphbar{It is to assure that section of code is working as it is supposed to work}
-\end{frame}
-
-\begin{frame}[fragile]
-    \frametitle{Example}
-    \begin{block}{Problem Statement}
-      Write a function to check whether a given input
-      string is a palindrome.
-    \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
-    \frametitle{Function: palindrome.py}
-\begin{lstlisting}    
-def is_palindrome(input_str):
-  return input_str == input_str[::-1]
-\end{lstlisting}    
-\end{frame}
-
-\begin{frame}[fragile]
-    \frametitle{Test for the palindrome: palindrome.py}
-\begin{lstlisting}    
-def test_function_normal_words():
-  input = "noon"
-  assert is_palindrome(input) == True
-
-if __name__ == "main'':
-  test_function_normal_words()
-\end{lstlisting}    
-\end{frame}
-
-\begin{frame}[fragile]
-    \frametitle{Running the tests.}
-\begin{lstlisting}    
-$ nosetests palindrome.py 
-.
-----------------------------------------------
-Ran 1 test in 0.001s
-
-OK
-\end{lstlisting}    
-\end{frame}
-
-\begin{frame}[fragile]
-    \frametitle{Exercise: Including new tests.}
-\begin{lstlisting}    
-def test_function_ignore_cases_words():
-  input = "Noon"
-  assert is_palindrome(input) == True
-\end{lstlisting}
-     \vspace*{0.25in}
-     Check\\
-     \PythonCode{$ nosetests palindrome.py} \\
-     \begin{block}{Task}
-     Tweak the code to pass this test.
-     \end{block}
-\end{frame}
-
-%\begin{frame}[fragile]
-%    \frametitle{Lets write some test!}
-%\begin{lstlisting}    
-%#for form of equation y=mx+c
-%#given m and c for two equation,
-%#finding the intersection point.
-%def intersect(m1,c1,m2,c2):
-%    x = (c2-c1)/(m1-m2)
-%    y = m1*x+c1
-%    return (x,y)
-%\end{lstlisting}
-%
-%Create a simple test for this
-%
-%function which will make it fail.
-%
-%\inctime{15} 
-%\end{frame}
-%
-
-%% \begin{frame}[fragile]
-%%     \frametitle{Exercise}
-%%     Based on Euclid's algorithm:
-%%     \begin{center}
-%%     $gcd(a,b)=gcd(b,b\%a)$
-%%     \end{center}
-%%     gcd function can be written as:
-%%     \begin{lstlisting}
-%%     def gcd(a, b):
-%%       if a%b == 0: return b
-%%       return gcd(b, a%b)
-%%     \end{lstlisting}
-%%     \vspace*{-0.15in}
-%%     \begin{block}{Task}
-%%       \begin{itemize}
-%%       \item Write at least 
-%%         two tests for above mentioned function.
-%%       \item Write a non recursive implementation
-%%       of gcd(), and test it using already 
-%%       written tests.
-%%       \end{itemize}
-%%     \end{block}
-    
-%% \inctime{15} 
-%% \end{frame}
-
-\begin{frame}
-  \frametitle{Summary}
-We have coverd:
-  \begin{itemize}
-  \item Following and Resolving Error Messages.
-  \item Exceptions.
-  \item Handling exceptions
-  \item Approach for Debugging.
-  \item Writting and running tests.
-  \end{itemize}
-\end{frame}
-
-\end{document}
+% \section{Test Driven Approach}
+% \begin{frame}
+%     \frametitle{Need for Testing!}
+%    
+%     \begin{itemize}
+%         \item Quality
+%         \item Regression
+%         \item Documentation
+%     \end{itemize}
+%     %% \vspace*{0.25in}
+%     %% \emphbar{It is to assure that section of code is working as it is supposed to work}
+% \end{frame}
+% 
+% \begin{frame}[fragile]
+%     \frametitle{Example}
+%     \begin{block}{Problem Statement}
+%       Write a function to check whether a given input
+%       string is a palindrome.
+%     \end{block}
+% \end{frame}
+% 
+% \begin{frame}[fragile]
+%     \frametitle{Function: palindrome.py}
+% \begin{lstlisting}    
+% def is_palindrome(input_str):
+%   return input_str == input_str[::-1]
+% \end{lstlisting}    
+% \end{frame}
+% 
+% \begin{frame}[fragile]
+%     \frametitle{Test for the palindrome: palindrome.py}
+% \begin{lstlisting}    
+% def test_function_normal_words():
+%   input = "noon"
+%   assert is_palindrome(input) == True
+% 
+% if __name__ == "main'':
+%   test_function_normal_words()
+% \end{lstlisting}    
+% \end{frame}
+% 
+% \begin{frame}[fragile]
+%     \frametitle{Running the tests.}
+% \begin{lstlisting}    
+% $ nosetests palindrome.py 
+% .
+% ----------------------------------------------
+% Ran 1 test in 0.001s
+% 
+% OK
+% \end{lstlisting}    
+% \end{frame}
+% 
+% \begin{frame}[fragile]
+%     \frametitle{Exercise: Including new tests.}
+% \begin{lstlisting}    
+% def test_function_ignore_cases_words():
+%   input = "Noon"
+%   assert is_palindrome(input) == True
+% \end{lstlisting}
+%      \vspace*{0.25in}
+%      Check\\
+%      \PythonCode{$ nosetests palindrome.py} \\
+%      \begin{block}{Task}
+%      Tweak the code to pass this test.
+%      \end{block}
+% \end{frame}
+% 
+% %\begin{frame}[fragile]
+% %    \frametitle{Lets write some test!}
+% %\begin{lstlisting}    
+% %#for form of equation y=mx+c
+% %#given m and c for two equation,
+% %#finding the intersection point.
+% %def intersect(m1,c1,m2,c2):
+% %    x = (c2-c1)/(m1-m2)
+% %    y = m1*x+c1
+% %    return (x,y)
+% %\end{lstlisting}
+% %
+% %Create a simple test for this
+% %
+% %function which will make it fail.
+% %
+% %\inctime{15} 
+% %\end{frame}
+% %
+% 
+% %% \begin{frame}[fragile]
+% %%     \frametitle{Exercise}
+% %%     Based on Euclid's algorithm:
+% %%     \begin{center}
+% %%     $gcd(a,b)=gcd(b,b\%a)$
+% %%     \end{center}
+% %%     gcd function can be written as:
+% %%     \begin{lstlisting}
+% %%     def gcd(a, b):
+% %%       if a%b == 0: return b
+% %%       return gcd(b, a%b)
+% %%     \end{lstlisting}
+% %%     \vspace*{-0.15in}
+% %%     \begin{block}{Task}
+% %%       \begin{itemize}
+% %%       \item Write at least 
+% %%         two tests for above mentioned function.
+% %%       \item Write a non recursive implementation
+% %%       of gcd(), and test it using already 
+% %%       written tests.
+% %%       \end{itemize}
+% %%     \end{block}
+%     
+% %% \inctime{15} 
+% %% \end{frame}
\ No newline at end of file