day1/Session-2.tex
author Madhusudan.C.S <madhusudancs@gmail.com>
Fri, 09 Oct 2009 12:59:55 +0530
changeset 86 f657495cf8b2
parent 54 c3fe152b3539
child 87 cd29428cd8f5
permissions -rwxr-xr-x
Final set of changes.
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>
14
55fb6114cff9 Stripped the slides irrelevant to this session.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
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,
18
2a70a7ef7e62 Added \bfseries to basicstyle for lstset.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 15
diff changeset
    36
    basicstyle=\ttfamily\bfseries,
5
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: 21
diff changeset
    76
\title[Basic Python]{Python:\\Functions and basic data structures}
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: 21
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}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
    81
\date[] {10, October 2009\\Day 1, Session 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
    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
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   113
\section{Control Flow}
15
1bc961ae4ddd Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 14
diff changeset
   114
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   115
\subsection{Exercises}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
\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
   117
  \frametitle{Problem set 1}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
  \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
   119
    \item All the problems can be\\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
      solved using \kwrd{if} and \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
   121
  \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
   122
\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
   123
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
\begin{frame}{Problem 1.1}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
  Write a program that displays all three digit numbers that are equal to the sum of the cubes of their digits. That is, print numbers $abc$ that have the property $abc = a^3 + b^3 + c^3$\\
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   126
\begin{block}
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   127
{Information...}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
These are called $Armstrong$ numbers.
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   129
\end{block}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
\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
   131
  
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
\begin{frame}{Problem 1.2 - Collatz sequence}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
\begin{enumerate}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
  \item Start with an arbitrary (positive) integer. 
15
1bc961ae4ddd Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 14
diff changeset
   135
  \item If the number is even, divide by 2; if the number is odd, multiply by 3 and add 1.
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
  \item Repeat the procedure with the new number.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
  \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
\end{enumerate}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
    Write a program that accepts the starting value and prints out the Collatz sequence.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
\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
   142
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
\begin{frame}[fragile]{Problem 1.4}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
  Write a program that prints the following pyramid on the screen. 
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{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
1
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
2  2
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
3  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
   149
4  4  4  4
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
  \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
   151
The number of lines must be obtained from the user as input.\\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
\pause
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
When can your code fail?
15
1bc961ae4ddd Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 14
diff changeset
   154
\only<2->{\inctime{20}}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
\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
   156
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
1bc961ae4ddd Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 14
diff changeset
   158
% TIME: 20 m, running 20m 
5
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
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   161
\section{Functions}
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   162
\subsection{Defining}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
\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
   164
\frametitle{Functions: examples}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
  \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
   166
def signum( r ):
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
    """returns 0 if r is zero
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
    -1 if r is negative
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
    +1 if r is positive"""
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
    if r < 0:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
        return -1
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
    elif r > 0:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
        return 1
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
    else:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
        return 0
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{Functions: examples}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
  \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
   182
def pad( n, size ): 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
    """pads integer n with spaces
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
    into a string of length size
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
    """
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
    SPACE = ' '
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
    s = str( n )
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
    padSize = size - len( s )
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
    return padSize * SPACE + s
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
  \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
   191
\pause
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
What about \%3d?
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
\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
   194
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
\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
   196
  {What does this function do?}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
  \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
   198
def what( 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
    if n < 0: n = -n
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
    while n > 0:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
        if n % 2 == 1:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
            return False
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
        n /= 10
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
    return True
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{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
\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
   207
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
\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
   209
  {What does this function do?}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
\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
   211
def what( n ):
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
    i = 1    
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
    while i * i < n:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
        i += 1
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
    return i * i == n, i
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
  \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
   217
\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
   218
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   219
\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
   220
  {What does this function do?}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
  \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
   222
def what( n, x ):
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
    z = 1.0
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
    if n < 0:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
        x = 1.0 / x
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
        n = -n
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
    while n > 0:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
        if n % 2 == 1:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   229
            z *= x
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   230
        n /= 2
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
        x *= x
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232
    return z
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   233
  \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
   234
\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
   235
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   236
\subsection{Built-in functions}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   237
\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
   238
  {Before writing a function}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   239
  \begin{itemize}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   240
      \item Variety of builtin functions are available
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   241
      \item \typ{abs, any, all, len, max, min}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   242
      \item \typ{pow, range, sum, type}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   243
      \item Refer here:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   244
          \url{http://docs.python.org/library/functions.html}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
  \end{itemize}
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   246
  \inctime{10} 
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   247
\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
   248
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   249
% TIME: 10 m, running 30m 
5
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
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   252
\subsection{Exercises}
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   253
\begin{frame}{Problem set 2: Problem 2.1}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
  Write a function to return the gcd of two numbers.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
\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
   256
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
\begin{frame}{Problem 2.2}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   258
Write a program to print all primitive pythagorean triads (a, b, c) where a, b are in the range 1---100 \\
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   259
A pythagorean triad $(a,b,c)$ has the property $a^2 + b^2 = c^2$.\\By primitive we mean triads that do not `depend' on others. For example, (4,3,5) is a variant of (3,4,5) and hence is not primitive. And (10,24,26) is easily derived from (5,12,13) and is also not primitive.
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   260
\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
   261
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   262
\begin{frame}{Problem 2.3}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   263
  Write a program that generates a list of all four digit numbers that have all their digits even and are perfect squares.\newline\\\emph{For example, the output should include 6400 but not 8100 (one digit is odd) or 4248 (not a perfect square).}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   264
\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
   265
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   266
\begin{frame}{Problem 2.4}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   267
  The aliquot of a number is defined as: the sum of the \emph{proper} divisors of the number. For example, aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16.\\
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   268
  Write a function that returns the aliquot number of a given number. 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   269
\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
   270
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{frame}{Problem 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
   272
  A pair of numbers (a, b) is said to be \alert{amicable} if the aliquot number of a is b and the aliquot number of b is a.\\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   273
  Example: \texttt{220, 284}\\
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   274
  Write a program that prints all four digit amicable pairs.
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   275
  \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
   276
\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
   277
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   278
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   279
% TIME: 25 m, running 55m 
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   280
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   281
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   282
\section{Lists}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   283
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   284
\subsection{Manipulating}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   285
\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
   286
  \frametitle{List creation and indexing}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   287
\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
   288
>>> a = [] # An empty list.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   289
>>> a = [1, 2, 3, 4] # More useful.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   290
>>> len(a) 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   291
4
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   292
>>> a[0] + a[1] + a[-1]
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   293
7
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   294
\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
   295
  \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
   296
  \item Indices start with ?
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   297
  \item Negative indices indicate ?
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   298
  \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
   299
\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
   300
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   301
\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
   302
  \frametitle{List: slices}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   303
  \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
   304
  \item Slicing is a basic operation
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   305
  \item \typ{list[initial:final:step]}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   306
  \item  The step is optional
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   307
  \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
   308
\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
   309
>>> a[1:3] # A slice.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   310
[2, 3]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   311
>>> a[1:-1]
15
1bc961ae4ddd Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 14
diff changeset
   312
[2, 3]
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   313
>>> a[1:] == a[1:-1]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   314
False  
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{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   316
Explain last result
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   317
\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
   318
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   319
\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
   320
  \frametitle{List: more slices}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   321
\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
   322
>>> a[0:-1:2] # Notice the step!
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   323
[1, 3]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   324
>>> a[::2]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   325
[1, 3]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   326
>>> a[-1::-1]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   327
\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
   328
What do you think the last one will do?
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   329
  \emphbar{Note: Strings also use same indexing and slicing.}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   330
\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
   331
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   332
\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
   333
  \frametitle{List: examples}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   334
\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
   335
>>> a = [1, 2, 3, 4]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   336
>>> a[:2]
15
1bc961ae4ddd Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 14
diff changeset
   337
[1, 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
   338
>>> a[0:-1:2]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   339
[1, 3]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   340
\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
   341
\pause
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   342
\alert{Lists are mutable (unlike strings)}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   343
\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
   344
>>> a[1] = 20
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   345
>>> a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   346
[1, 20, 3, 4]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   347
\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
   348
\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
   349
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   350
\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
   351
  \frametitle{Lists are mutable and heterogenous}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   352
\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
   353
>>> a = ['spam', 'eggs', 100, 1234]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   354
>>> a[2] = a[2] + 23
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   355
>>> a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   356
['spam', 'eggs', 123, 1234]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   357
>>> a[0:2] = [1, 12] # Replace items
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   358
>>> a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   359
[1, 12, 123, 1234]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   360
>>> a[0:2] = [] # Remove items
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   361
>>> a.append( 12345 )
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   362
>>> a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   363
[123, 1234, 12345]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   364
\end{lstlisting}
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   365
\inctime{10}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   366
\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
   367
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   368
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   369
% TIME: 10 m, running 65m 
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   370
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   371
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   372
\subsection{Methods}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   373
\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
   374
  \frametitle{List methods}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   375
\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
   376
>>> a = ['spam', 'eggs', 1, 12]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   377
>>> a.reverse() # in situ
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   378
>>> a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   379
[12, 1, 'eggs', 'spam']
15
1bc961ae4ddd Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 14
diff changeset
   380
>>> a.append(['x', 1])
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   381
>>> a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   382
[12, 1, 'eggs', 'spam', ['x', 1]]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   383
>>> a.extend([1,2]) # Extend 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
   384
>>> a.remove( 'spam' )
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   385
>>> a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   386
[12, 1, 'eggs', ['x', 1], 1, 2]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   387
\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
   388
\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
   389
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   390
\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
   391
  \frametitle{List containership}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   392
  \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
   393
>>> a = ['cat', 'dog', 'rat', 'croc']
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   394
>>> 'dog' in a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   395
True
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   396
>>> 'snake' in a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   397
False
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   398
>>> 'snake' not in a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   399
True
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   400
>>> 'ell' in 'hello world'
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   401
True
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   402
  \end{lstlisting}
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   403
  \inctime{5}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   404
\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
   405
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   406
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   407
% TIME: 5 m, running 70m 
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   408
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   409
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   410
\section{Tuples}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   411
\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
   412
  \frametitle{Tuples: immutable}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   413
\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
   414
>>> t = (0, 1, 2)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   415
>>> print t[0], t[1], t[2], t[-1] 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   416
0 1 2 2
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   417
>>> t[0] = 1
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   418
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
   419
  File "<stdin>", line 1, in ?
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   420
TypeError: object does not support
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   421
item assignment
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   422
\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
   423
\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
   424
    \item Multiple return values are actually a tuple.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   425
    \item Exchange is tuple (un)packing
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   426
\end{itemize}
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   427
\inctime{5}
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   428
\end{frame}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   429
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   430
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   431
% TIME: 5 m, running 75m 
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   432
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   433
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   434
\section{for and range()}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   435
\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
   436
  \frametitle{\typ{range()} function}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   437
  \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
   438
>>> range(7)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   439
[0, 1, 2, 3, 4, 5, 6]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   440
>>> range( 3, 9)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   441
[3, 4, 5, 6, 7, 8]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   442
>>> range( 4, 17, 3)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   443
[4, 7, 10, 13, 16]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   444
>>> range( 5, 1, -1)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   445
[5, 4, 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
   446
>>> range( 8, 12, -1)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   447
[]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   448
  \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
   449
\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
   450
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   451
\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
   452
  \frametitle{\typ{for\ldots range(\ldots)} idiom}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   453
  \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
   454
In [83]: for i in range(5):
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   455
   ....:     print i, i * i
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   456
   ....:     
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   457
   ....:     
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   458
0 0
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   459
1 1
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   460
2 4
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   461
3 9
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   462
4 16
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   463
\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
   464
\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
   465
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   466
\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
   467
  \frametitle{\typ{for}: the list companion}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   468
  
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   469
  \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
   470
In [84]: a = ['a', 'b', 'c']
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   471
In [85]: for x in a:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   472
   ....:    print x, chr( ord(x) + 10 )
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   473
   ....:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   474
a  k
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   475
b  l
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   476
c  m
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   477
  \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
   478
  Iterating over the list and not the index + reference\\
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   479
  what if you want the index?
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   480
\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
   481
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   482
\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
   483
  \frametitle{\typ{for}: the list companion}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   484
  \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
   485
In [89]: for p, ch in enumerate( a ):
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   486
   ....:     print p, ch
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   487
   ....:     
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   488
   ....:     
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   489
0 a
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   490
1 b
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   491
2 c
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   492
  \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
   493
Try: \typ{print enumerate(a)}
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   494
\inctime{10}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   495
\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
   496
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   497
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
844b81ad2a3c Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 18
diff changeset
   498
% TIME: 10 m, running 85m 
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   499
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   500
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   501
\begin{frame}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   502
  \frametitle{What did we learn?}
51
d3a8a9556a90 Added What did we learn at the end of session 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 50
diff changeset
   503
  \begin{itemize}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   504
    \item Control flow in action
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   505
    \item Functions
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   506
    \item Manipulating Lists 
51
d3a8a9556a90 Added What did we learn at the end of session 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 50
diff changeset
   507
    \item Tuples
d3a8a9556a90 Added What did we learn at the end of session 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 50
diff changeset
   508
    \item range() function
d3a8a9556a90 Added What did we learn at the end of session 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 50
diff changeset
   509
    \item for loops
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   510
    \item for...range() idiom
51
d3a8a9556a90 Added What did we learn at the end of session 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 50
diff changeset
   511
  \end{itemize}
15
1bc961ae4ddd Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 14
diff changeset
   512
\end{frame}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   513
\end{document}