summaryrefslogtreecommitdiff
path: root/day1
diff options
context:
space:
mode:
Diffstat (limited to 'day1')
-rwxr-xr-xday1/Session-1.tex50
-rwxr-xr-xday1/Session-3.tex144
-rw-r--r--day1/dummyfile10
-rw-r--r--day1/handout.tex8
-rw-r--r--day1/links.tex22
5 files changed, 184 insertions, 50 deletions
diff --git a/day1/Session-1.tex b/day1/Session-1.tex
index e17e9ae..ffa5d43 100755
--- a/day1/Session-1.tex
+++ b/day1/Session-1.tex
@@ -1,5 +1,5 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Tutorial slides on Python.
+%Tutorial slides on Python.
%
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
% Copyright (c) 2005-2009, Prabhu Ramachandran
@@ -33,7 +33,7 @@
\usepackage{listings}
\lstset{language=Python,
- basicstyle=\ttfamily,
+ basicstyle=\ttfamily\bfseries,
commentstyle=\color{red}\itshape,
stringstyle=\color{darkgreen},
showstringspaces=false,
@@ -134,12 +134,16 @@
% * Add slides on reference counting.
\section{Agenda}
-\begin{frame}{About the Workshop}
+\begin{frame}{About the Workshop, Day 1}
\begin{description}
\item[Day 1, Session 1] Sat 09:30--11:00
\item[Day 1, Session 2] Sat 11:15--12:45
\item[Day 1, Session 3] Sat 13:45--15:15
\item[Day 1, Session 4] Sat 15:30--17:00
+ \end{description}
+\end{frame}
+\begin{frame}{About the Workshop, Day 2}
+ \begin{description}
\item[Day 2, Quiz] Sun 09:00--09:30
\item[Day 2, Session 1] Sun 09:30--11:00
\item[Day 2, Session 2] Sun 11:15--12:45
@@ -151,21 +155,22 @@
\begin{frame}{About the Workshop}
\begin{block}{Intended Audience}
\begin{itemize}
- \item Aimed at Engg., Mathematics and Science teachers.
+ \item Engg., Mathematics and Science teachers.
\item Interested students from similar streams.
\end{itemize}
\end{block}
- \begin{block}{Goal}
- Successful participants will be able to use python as their scripting and problem solving language.
+ \begin{block}{Goal:}
+ Successful participants will be able to
+ \begin{itemize}
+ \item use Python as their scripting and problem solving language.
+ \item train the students to use Python for the same
+ \end{itemize}
\end{block}
\end{frame}
\begin{frame}{Checklist}
- \begin {block}{Live Python}
- Have you booted using the Live Python DVD?
- \end {block}
- \begin{block}{python}
+ \begin{block}{python}
Type python at the command line. Do you see version 2.5 or later?
\end{block}
\begin{block}{IPython}
@@ -308,7 +313,7 @@
\end{center}
\end{frame}
-\begin{frame}{More exercises?}
+\begin{frame}{More exercises}
\begin{center}
\begin{block}{Round sums}
How to round a number to the nearest 5 paise?\\
@@ -508,7 +513,7 @@ Out[8]: False
\end{block}
\end{frame}
-\begin{frame}[fragile]{Surprise! strings!!}
+\begin{frame}[fragile]{String formatting}
\begin{lstlisting}
In [11]: x, y = 1, 1.2
In [12]: 'x is %s, y is %s' %(x, y)
@@ -523,10 +528,15 @@ Out[12]: 'x is 1, y is 1.234'
\end{frame}
\begin{frame}
- {Interlude}
+ {A classic problem}
\begin{block}
- {A classic problem}
- How to interchange values of two variables? Please note that the type of either variable is unknown and it is not necessary that both be of the same type even!
+ {Interchange values}
+ How to interchange values of two variables?
+ \end{block}
+ \pause
+ \begin{block}{Note:}
+ This Python idiom works for all types of variables.\\
+They need not be of the same type!
\end{block}
\inctime{30}
\end{frame}
@@ -568,10 +578,9 @@ World
\begin{itemize}
\item aka scripts
\item use your editor
- \item Note that white space is the way to specify blocks!
\item extension \typ{.py}
\item run with \texttt{python hello.py} at the command line
- \item in IPython\ldots
+ \item in IPython using \kwrd{\%run}
\end{itemize}
\end{frame}
@@ -627,10 +636,11 @@ while b < 10:
\begin{frame}{So what have we learnt so far?}
\begin{itemize}
\item The interactive interpreter
- \item Basic Data Types-Numbers
- \item \typ{if/elif/else, while}
- \item Simple IO
+ \item Basic Data Types
\item Creating and running a Python script
+ \item \kwrd{if/elif/else}
+ \item Simple IO
+ \item Basic Looping with \kwrd{while}
\end{itemize}
\end{frame}
\end{document}
diff --git a/day1/Session-3.tex b/day1/Session-3.tex
index 0a6cf81..d518781 100755
--- a/day1/Session-3.tex
+++ b/day1/Session-3.tex
@@ -33,7 +33,7 @@
\usepackage{listings}
\lstset{language=Python,
- basicstyle=\ttfamily,
+ basicstyle=\ttfamily\bfseries,
commentstyle=\color{red}\itshape,
stringstyle=\color{darkgreen},
showstringspaces=false,
@@ -86,12 +86,12 @@
%% Delete this, if you do not want the table of contents to pop up at
-%% the beginning of each subsection:
-\AtBeginSubsection[]
+%% the beginning of each section:
+\AtBeginSection[]
{
\begin{frame}<beamer>
\frametitle{Outline}
- \tableofcontents[currentsection,currentsubsection]
+ \tableofcontents[currentsection]
\end{frame}
}
@@ -110,19 +110,15 @@
\titlepage
\end{frame}
-\begin{frame}
- \frametitle{Outline}
- \tableofcontents
- % You might wish to add the option [pausesections]
-\end{frame}
-
-\section{Python}
+\section{\typ{for}, Lists and Tuples}
-\subsection{Problem Set based on Lists and Tuples}
-
-\begin{frame}
- {Problem set 3}
- As you can guess, idea is to use \kwrd{for}!
+\begin{frame}{Quick Recap}
+ \begin{itemize}
+ \item List indexing and slicing
+ \item The \kwrd{range()} function
+ \item \kwrd{for}
+ \item Iterating lists and tuples using \kwrd{for} and \kwrd{range()}
+ \end{itemize}
\end{frame}
\begin{frame}{Problem 3.1}
@@ -149,7 +145,7 @@
\end{frame}
\begin{frame}[fragile]
- \frametitle{Problem 3.4a (optional)}
+ \frametitle{Problem 3.4}
Use the \typ{linspace} function and generate a list of N tuples of the form\\
\typ{[($x_1$,f($x_1$)),($x_2$,f($x_2$)),\ldots,($x_N$,f($x_N$))]}\\for the following functions,\begin{itemize}
@@ -159,7 +155,7 @@ Use the \typ{linspace} function and generate a list of N tuples of the form\\
\end{frame}
\begin{frame}[fragile]
- \frametitle{Problem 3.4b (optional)}
+ \frametitle{Problem 3.5}
Using the tuples generated earlier, determine the intervals where the roots of the functions lie.
@@ -170,7 +166,7 @@ Use the \typ{linspace} function and generate a list of N tuples of the form\\
% TIME: 15 m, running 185m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\subsection{IO}
+\section{Parsing}
\begin{frame}[fragile]
\frametitle{Simple tokenizing and parsing}
@@ -190,6 +186,8 @@ for word in s.split():
\end{lstlisting}
\end{frame}
+\section{Input/Output}
+
\begin{frame}[fragile]
\frametitle{File handling}
\begin{lstlisting}
@@ -213,13 +211,59 @@ Writing files
\begin{frame}[fragile]
\frametitle{File and \kwrd{for}}
\begin{lstlisting}
->>> f = open('/path/to/file_name')
+$ cat dummyfile
+One 1
+Two 2
+Three 3
+Four 4
+Five 5
+Six 6
+Seven 7
+Eight 8
+Nine 9
+Ten 10
+\end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{File and \kwrd{for}}
+\begin{lstlisting}
+>>> f = open('dummyfile')
>>> for line in f:
... print line
...
\end{lstlisting}
\end{frame}
+\begin{frame}[fragile]
+ \frametitle{File and \kwrd{for}}
+\begin{lstlisting}
+In [1]: f = open('dummyfile')
+
+In [2]: for line in f:
+ ...: print line
+ ...:
+\end{lstlisting}
+
+\begin{columns}
+ \column{0.3\textwidth}
+
+\begin{lstlisting}
+One 1
+
+Two 2
+
+Three 3
+\end{lstlisting}
+ \column{0.6\textwidth}
+\pause
+\begin{block}{What happens when ...}
+the \kwrd{print line} is replaced by \kwrd{print line,}
+\end{block}
+\end{columns}
+\ldots
+\end{frame}
+
\begin{frame}{Problem 4.2}
The given file has lakhs of records in the form:\\
\typ{RGN;ID;NAME;MARK1;\ldots;MARK5;TOTAL;PFW}\\
@@ -239,7 +283,7 @@ Writing files
% TIME: 30 m, running 215m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\subsection{Modules}
+\section{Modules}
\begin{frame}[fragile]
{Modules}
@@ -347,14 +391,15 @@ def lcm(a, b):
\inctime{25}
\end{frame}
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TIME: 25 m, running 230m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\subsection{Coding Style in Python}
+\section{Coding Style}
\begin{frame}{Readability and Consistency}
\begin{itemize}
- \item Readability Counts!-Code is read more often than its written.
+ \item Readability Counts!\\Code is read more often than its written.
\item Consistency!
\item Know when to be inconsistent.
\end{itemize}
@@ -393,12 +438,16 @@ def lcm(a, b):
\item Ending the docstrings
\item One liner docstrings
\end{itemize}
+More information at PEP8: http://www.python.org/dev/peps/pep-0008/
\inctime{10}
\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% TIME: 10 m, running 240m
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\subsection{Objects}
-\begin{frame}{Objects in Python}
+\section{Objects}
+\begin{frame}{Objects in general}
\begin{itemize}
\item What is an Object? (Types and classes)
\item identity
@@ -407,8 +456,35 @@ def lcm(a, b):
\end{itemize}
\end{frame}
+\begin{frame}{Almost everything is an Object!}
+ \begin{itemize}
+ \item \typ{list}
+ \item \typ{tuple}
+ \item \typ{string}
+ \item \typ{dictionary}
+ \item \typ{function}
+ \item Of course, user defined class objects!
+ \end{itemize}
+\end {frame}
+
+\begin{frame}{Using Objects}
+ \begin{itemize}
+ \item Creating Objects: Initialization
+ \item Object Manipulation: Object methods and ``.'' operator
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{IPython Examples}
+ \begin{lstlisting}
+In [1]: l = [] #Initialising a list object
+In [2]: l?
+In [3]: l.<tab>
+ \end{lstlisting}
+\end{frame}
+
\begin{frame}[fragile]
- \frametitle{Why are they useful?}
+ \frametitle{Objects provide consistency}
\small
\begin{lstlisting}
for element in (1, 2, 3):
@@ -430,9 +506,17 @@ for line in urllib2.urlopen('http://site.com'):
\inctime{10}
\end{frame}
-\begin{frame}
- \frametitle{What did we learn?}
- \tableofcontents
- % You might wish to add the option [pausesections]
+\section{Summary}
+
+\begin{frame}{What have we learnt so far?}
+ \begin{itemize}
+ \item Operating on lists and tuples using \kwrd{for}
+ \item Simple string tokenizing and parsing
+ \item Writing to and Reading from files using \kwrd{for}
+ \item Using and writing Python Modules
+ \item Coding Style
+ \item Objects in Python
+ \end{itemize}
\end{frame}
+
\end{document}
diff --git a/day1/dummyfile b/day1/dummyfile
new file mode 100644
index 0000000..a50b33a
--- /dev/null
+++ b/day1/dummyfile
@@ -0,0 +1,10 @@
+One 1
+Two 2
+Three 3
+Four 4
+Five 5
+Six 6
+Seven 7
+Eight 8
+Nine 9
+Ten 10 \ No newline at end of file
diff --git a/day1/handout.tex b/day1/handout.tex
index c16725a..a4f1c88 100644
--- a/day1/handout.tex
+++ b/day1/handout.tex
@@ -670,4 +670,12 @@ for i in range(1, 100):
squares = [i*i for i in range(1, 100)
if i % 10 in [1, 2, 5, 7]]
\end{verbatim}
+\newpage
+\section{Further Reference:}
+\begin{itemize}
+ \item Most referred and trusted material for learning \emph{Python} language is available at docs.python.org/tutorial/
+ \item ``may be one of the thinnest programming language books on my shelf, but it's also one of the best.'' -- \emph{Slashdot, AccordianGuy, September 8, 2004}- available at diveintopython.org/
+ \item How to Think Like a Computer Scientist: Learning with Python available at http://www.openbookproject.net/thinkcs/python/english/ \\
+ ``The concepts covered here apply to all programming languages and to problem solving in general.'' -- \emph{Guido van Rossum, creator of Python}
+\end{itemize}
\end{document}
diff --git a/day1/links.tex b/day1/links.tex
new file mode 100644
index 0000000..7734d47
--- /dev/null
+++ b/day1/links.tex
@@ -0,0 +1,22 @@
+\documentclass[12pt]{article}
+\title{Links and References}
+\author{Asokan Pichai\\Prabhu Ramachandran}
+\begin{document}
+\maketitle
+\begin{itemize}
+ \item Most referred and trusted material for learning \emph{Python} language is available at \url{http://docs.python.org/tutorial/}
+ \item ``may be one of the thinnest programming language books on my shelf, but it's also one of the best.'' -- \emph{Slashdot, AccordianGuy, September 8, 2004}- available at \url{http://diveintopython.org/}
+ \item How to Think Like a Computer Scientist: Learning with Python available at \url{http://www.openbookproject.net/thinkcs/python/english/}\\``The concepts covered here apply to all programming languages and to problem solving in general.'' -- \emph{Guido van Rossum, creator of Python}
+ \item Some assorted articles related to Python \url{http://effbot.org/zone/index.htm}
+ \item To read more on strings refer to: \\ \url{http://docs.python.org/library/stdtypes.html#string-methods}
+ \item For documentation on IPython refer: \\ \url{http://ipython.scipy.org/moin/Documentation}
+ \item Documentation for Numpy and Scipy is available at: \url{http://docs.scipy.org/doc/}
+ \item For "recipes" or worked examples of commonly-done tasks in SciPy explore: \url{http://www.scipy.org/Cookbook/}
+ \item User Guide for Mayavi is the best place to look for Mayavi Documentation, available at: \\ \url{http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/}
+ \item Explore examples and plots based on matplotlib at \\ \url{http://matplotlib.sourceforge.net/examples/index.html}
+ \item One stop go for Sage is \url{http://www.sagemath.org/doc/}
+ \item Central page for all SymPy’s documentation is at \\ \url{http://docs.sympy.org/}
+ \item For videos from basics to advanced Python check out: \\ \url{http://www.archive.org/search.php?query=scipy09}
+
+\end{itemize}
+\end{document}