day1/Session-3.tex
author Santosh G. Vattam <vattam.santosh@gmail.com>
Wed, 07 Oct 2009 00:50:06 +0530
changeset 48 7f4c51382f89
parent 47 21de307e6823
parent 46 63704b5650f1
child 49 2adb90f9e287
child 52 fccb3551c7d5
permissions -rwxr-xr-x
Merged branches from Madhusudan C.S.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
% Tutorial slides on Python.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
46
63704b5650f1 Changed the copyright and Institute for all the sessions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 42
diff changeset
     5
% Copyright (c) 2005-2009, Prabhu Ramachandran
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
\documentclass[14pt,compress]{beamer}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
%\documentclass[draft]{beamer}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
%\documentclass[compress,handout]{beamer}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
%\usepackage{pgfpages} 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
% Modified from: generic-ornate-15min-45min.de.tex
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
\mode<presentation>
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
{
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
  \usetheme{Warsaw}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
  \useoutertheme{split}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
  \setbeamercovered{transparent}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
\usepackage[english]{babel}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
\usepackage[latin1]{inputenc}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
%\usepackage{times}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
\usepackage[T1]{fontenc}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
% Taken from Fernando's slides.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
\usepackage{ae,aecompl}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
\usepackage{mathpazo,courier,euler}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
\usepackage[scaled=.95]{helvet}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
\definecolor{darkgreen}{rgb}{0,0.5,0}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
\usepackage{listings}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
\lstset{language=Python,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
    basicstyle=\ttfamily,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
    commentstyle=\color{red}\itshape,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
  stringstyle=\color{darkgreen},
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
  showstringspaces=false,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
  keywordstyle=\color{blue}\bfseries}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
% Macros
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
\newcommand{\emphbar}[1]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
{\begin{beamercolorbox}[rounded=true]{emphbar} 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
      {#1}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
 \end{beamercolorbox}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
\newcounter{time}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
\setcounter{time}{0}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
\newcommand{\typ}[1]{\texttt{#1}}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
%%% This is from Fernando's setup.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
% \usepackage{color}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
% % Use and configure listings package for nicely formatted code
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
% \usepackage{listings}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
% \lstset{
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
%    language=Python,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
%    basicstyle=\small\ttfamily,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
%    commentstyle=\ttfamily\color{blue},
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
%    stringstyle=\ttfamily\color{orange},
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
%    showstringspaces=false,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
%    breaklines=true,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
%    postbreak = \space\dots
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
% }
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
% Title page
46
63704b5650f1 Changed the copyright and Institute for all the sessions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 42
diff changeset
    76
\title[Basic Python]{Python:\\Modular Code, Handling Files and Objects}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
46
63704b5650f1 Changed the copyright and Institute for all the sessions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 42
diff changeset
    78
\author[FOSSEE Team] {Asokan Pichai\\Prabhu Ramachandran}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
    81
\date[] {Day 1, Session-3, 10, October 2009}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
%\logo{\pgfuseimage{iitmlogo}}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
%% Delete this, if you do not want the table of contents to pop up at
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
%% the beginning of each subsection:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
\AtBeginSubsection[]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
{
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
  \begin{frame}<beamer>
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
    \frametitle{Outline}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
    \tableofcontents[currentsection,currentsubsection]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
  \end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
% If you wish to uncover everything in a step-wise fashion, uncomment
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
% the following command: 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
%\beamerdefaultoverlayspecification{<+->}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
% DOCUMENT STARTS
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
\begin{document}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
\begin{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
  \titlepage
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
\section{Python}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   115
\subsection{Problem Set based on Lists and Tuples}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   116
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
\begin{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
  {Problem set 3}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
  As you can guess, idea is to use \kwrd{for}!
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
\begin{frame}{Problem 3.1}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
  Which of the earlier problems is simpler when we use \kwrd{for} instead of \kwrd{while}? 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
\begin{frame}{Problem 3.2}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
  Given an empty chessboard and one Bishop placed in any square, say (r, c), generate the list of all squares the Bishop could move to.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   129
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
  \frametitle{Problem 3.3}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
  Given two real numbers \typ{a, b}, and an integer \typ{N}, write a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
  function named \typ{linspace( a, b, N)} that returns an ordered list
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   135
  of \typ{N} points starting with \typ{a} and ending in \typ{b} and
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
  equally spaced.\\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
  For example, \typ{linspace(0, 5, 11)}, should return, \\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
\begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
[ 0.0 ,  0.5,  1.0 ,  1.5,  2.0 ,  2.5,  
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
  3.0 ,  3.5,  4.0 ,  4.5,  5.0 ]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
\end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
  \frametitle{Problem 3.4a (optional)}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
Use the \typ{linspace} function and generate a list of N tuples of the form\\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
\typ{[($x_1$,f($x_1$)),($x_2$,f($x_2$)),\ldots,($x_N$,f($x_N$))]}\\for the following functions,\begin{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
  \item \typ{f(x) = sin(x)}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
  \item \typ{f(x) = sin(x) + sin(10*x)}.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
\end{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
  \frametitle{Problem 3.4b (optional)}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
  Using the tuples generated earlier, determine the intervals where the roots of the functions lie.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   159
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   160
  \inctime{15}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   162
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   164
% TIME: 15 m, running 185m 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
\subsection{IO}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
  \frametitle{Simple tokenizing and parsing}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
  \begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
s = """The quick brown fox jumped
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
       over the lazy dog"""
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
for word in s.split():
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
    print word.capitalize()
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
  \end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
  \frametitle{Problem 4.1}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
  Given a string like, ``1, 3-7, 12, 15, 18-21'', produce the list \\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
  \begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
    [1,3,4,5,6,7,12,15,18,19,20,21]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
  \end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
  \frametitle{File handling}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
\begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
>>> f = open('/path/to/file_name')
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
>>> data = f.read() # Read entire file.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
>>> line = f.readline() # Read one line.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
>>> f.close() # close the file.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
\end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
Writing files
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
\begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
>>> f = open('/path/to/file_name', 'w')
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
>>> f.write('hello world\n')
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
>>> f.close()
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
\end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
\begin{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
    \item Everything read or written is a string
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
\end{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
\emphbar{Try \typ{file?} for more help}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
    \frametitle{File and \kwrd{for}}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
\begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
>>> f = open('/path/to/file_name')
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
>>> for line in f:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
...     print line
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
...
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
\end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
\begin{frame}{Problem 4.2}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
    The given file has lakhs of records in the form:\\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   219
    \typ{RGN;ID;NAME;MARK1;\ldots;MARK5;TOTAL;PFW}\\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
    Some entries may be empty.  Read the data from this file and print the
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
    name of the student with the maximum total marks.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
\begin{frame}{Problem 4.3}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
    For the same data file compute the average marks in different
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
    subjects, the student with the maximum mark in each subject and also
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
    the standard deviation of the marks.  Do this efficiently.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   229
    \inctime{30}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   230
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   233
% TIME: 30 m, running 215m 
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   234
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   235
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   236
\subsection{Modules}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   237
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   239
    {Modules}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   240
\begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   241
>>> sqrt(2)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   242
Traceback (most recent call last):
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   243
  File "<stdin>", line 1, in <module>
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   244
NameError: name 'sqrt' is not defined
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
>>> import math        
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   246
>>> math.sqrt(2)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   247
1.4142135623730951
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   248
\end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   249
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   250
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   251
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
    {Modules}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   253
  \begin{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
    \item The \kwrd{import} keyword ``loads'' a module
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
    \item One can also use:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
      \begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
>>> from math import sqrt
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   258
>>> from math import *
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   259
      \end{lstlisting}    
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   260
    \item What is the difference?
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   261
    \item \alert{Use the later only in interactive mode}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   262
    \end{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   263
  \emphbar{Package hierarchies}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   264
      \begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   265
>>> from os.path import exists
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   266
      \end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   267
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   268
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   269
\begin{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   270
  \frametitle{Modules: Standard library}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   271
  \begin{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   272
  \item Very powerful, ``Batteries included''
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   273
  \item Some standard modules:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   274
    \begin{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   275
    \item Math: \typ{math}, \typ{random}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   276
    \item Internet access: \typ{urllib2}, \typ{smtplib}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   277
    \item System, Command line arguments: \typ{sys}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   278
    \item Operating system interface: \typ{os}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   279
    \item Regular expressions: \typ{re}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   280
    \item Compression: \typ{gzip}, \typ{zipfile}, and \typ{tarfile}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   281
    \item And a whole lot more!
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   282
    \end{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   283
  \item Check out the Python Library reference:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   284
    \url{http://docs.python.org/library/}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   285
  \end{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   286
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   287
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   288
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   289
    {Modules of special interest}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   290
    \begin{description}[matplotlibfor2d]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   291
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   292
        \item[\typ{numpy}] Efficient, powerful numeric arrays
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   293
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   294
        \item[\typ{matplotlib}] Easy, interactive, 2D plotting
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   295
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   296
        \item[\typ{scipy}] statistics, optimization, integration, linear
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   297
            algebra, Fourier transforms, signal and image processing,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   298
            genetic algorithms, ODE solvers, special functions, and more
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   299
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   300
        \item[Mayavi] Easy, interactive, 3D plotting
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   301
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   302
    \end{description}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   303
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   304
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   305
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   306
    {Creating your own modules}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   307
  \begin{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   308
  \item Define variables, functions and classes in a file with a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   309
    \typ{.py} extension
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   310
  \item This file becomes a module!
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   311
  \item Accessible when in the current directory
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   312
  \item Use \typ{cd} in IPython to change directory
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   313
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   314
  \item Naming your module
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   315
      \end{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   316
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   317
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   318
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   319
  \frametitle{Modules: example}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   320
  \begin{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   321
# --- arith.py ---
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   322
def gcd(a, b):
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   323
    if a%b == 0: return b
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   324
    return gcd(b, a%b)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   325
def lcm(a, b):
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   326
    return a*b/gcd(a, b)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   327
# ------------------
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   328
>>> import arith
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   329
>>> arith.gcd(26, 65)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   330
13
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   331
>>> arith.lcm(26, 65)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   332
130
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   333
  \end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   334
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   335
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   336
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   337
  \frametitle{Problem 5.1}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   338
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   339
  Put all the functions you have written so far as part of the problems
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   340
  into one module called \typ{bprim.py} and use this module from IPython.
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   341
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   342
\inctime{25}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   343
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   344
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   345
% TIME: 25 m, running 230m 
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   346
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   347
27
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   348
\subsection{Coding Style in Python}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   349
\begin{frame}{Readability and Consistency}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   350
    \begin{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   351
        \item Readability Counts!-Code is read more often than its written.
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   352
        \item Consistency!
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   353
        \item Know when to be inconsistent.
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   354
      \end{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   355
\end{frame}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   356
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   357
\begin{frame}[fragile]
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   358
  \frametitle{Code Layout}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   359
  \begin{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   360
        \item Indentation
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   361
        \item Tabs or Spaces??
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   362
        \item Maximum Line Length
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   363
        \item Blank Lines
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   364
        \item Encodings
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   365
   \end{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   366
\end{frame}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   367
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   368
\begin{frame}{Whitespaces in Expressions}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   369
  \begin{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   370
        \item When to use extraneous whitespaces??
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   371
        \item When to avoid extra whitespaces??
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   372
        \item Use one statement per line
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   373
   \end{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   374
\end{frame}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   375
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   376
\begin{frame}{Comments}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   377
  \begin{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   378
        \item No comments better than contradicting comments
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   379
        \item Block comments
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   380
        \item Inline comments
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   381
   \end{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   382
\end{frame}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   383
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   384
\begin{frame}{Docstrings}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   385
  \begin{itemize}
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   386
        \item When to write docstrings?
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   387
        \item Ending the docstrings
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   388
        \item One liner docstrings
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   389
   \end{itemize}
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   390
\inctime{10}
27
ecf0f0e885f4 Updated Coding Style slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 26
diff changeset
   391
\end{frame}
47
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   392
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   393
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   394
\subsection{Objects}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   395
\begin{frame}{Objects in Python}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   396
    \begin{itemize}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   397
        \item What is an Object? (Types and classes)
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   398
        \item identity
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   399
        \item type
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   400
        \item method
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   401
      \end{itemize}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   402
\end{frame}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   403
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   404
\begin{frame}[fragile]
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   405
  \frametitle{Why are they useful?}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   406
  \small
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   407
  \begin{lstlisting}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   408
for element in (1, 2, 3):
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   409
    print element
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   410
for key in {'one':1, 'two':2}:
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   411
    print key
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   412
for char in "123":
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   413
    print char
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   414
for line in open("myfile.txt"):
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   415
    print line
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   416
for line in urllib2.urlopen('http://site.com'):
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   417
    print line
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   418
  \end{lstlisting}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   419
\end{frame}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   420
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   421
\begin{frame}{And the winner is \ldots OBJECTS!}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   422
  All objects providing a similar inteface can be used the same way.\\
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   423
  Functions (and others) are first-class objects. Can be passed to and returned from functions.
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   424
  \inctime{10}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   425
\end{frame}
21de307e6823 Updated session 1 slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 42
diff changeset
   426
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   427
\end{document}