author | Madhusudan.C.S <madhusudancs@gmail.com> |
Wed, 07 Oct 2009 14:42:38 +0530 | |
changeset 49 | 2adb90f9e287 |
parent 46 | 63704b5650f1 |
child 50 | aabaf8ec0a08 |
permissions | -rwxr-xr-x |
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 |
|
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} |
15
1bc961ae4ddd
Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
114 |
|
14
55fb6114cff9
Stripped the slides irrelevant to this session.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
5
diff
changeset
|
115 |
\subsection{Exercises on Control flow} |
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$\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
126 |
These are called $Armstrong$ numbers. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
127 |
\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
|
128 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
129 |
\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
|
130 |
\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
|
131 |
\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
|
132 |
\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
|
133 |
\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
|
134 |
\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
|
135 |
\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
|
136 |
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
|
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 |
\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
|
139 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
140 |
\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
|
141 |
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
|
142 |
\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
|
143 |
1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
\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
|
148 |
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
|
149 |
\pause |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
150 |
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
|
151 |
\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
|
152 |
\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
|
153 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
154 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
15
1bc961ae4ddd
Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
155 |
% 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
|
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 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
158 |
\subsection{Functions} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
159 |
\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
|
160 |
\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
|
161 |
\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
|
162 |
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
|
163 |
"""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
|
164 |
-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
|
165 |
+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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
else: |
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 0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
172 |
\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
|
173 |
\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
|
174 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
175 |
\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
|
176 |
\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
|
177 |
\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
|
178 |
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
|
179 |
"""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
|
180 |
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
|
181 |
""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
182 |
SPACE = ' ' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
\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
|
187 |
\pause |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
188 |
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
|
189 |
\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
|
190 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
191 |
\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
|
192 |
{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
|
193 |
\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
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
\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
|
202 |
\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
|
203 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
204 |
\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
|
205 |
{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
|
206 |
\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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
\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
|
213 |
\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
|
214 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
215 |
\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
|
216 |
{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
|
217 |
\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
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
\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
|
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 |
\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
|
233 |
{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
|
234 |
\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
|
235 |
\item Builtin functions for various and sundry |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
236 |
\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
|
237 |
\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
|
238 |
\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
|
239 |
\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
|
240 |
\end{itemize} |
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
241 |
\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
|
242 |
\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
|
243 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
244 |
% 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
|
245 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
246 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
247 |
\begin{frame}{Problem set 2} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
248 |
The focus is on writing functions and calling them. |
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}{Problem 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
|
252 |
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
|
253 |
\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
|
254 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
255 |
\begin{frame}{Problem 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
|
256 |
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 should not be displayed by our program. \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
257 |
Write a program to print primitive pythagorean triads. The program should generate all triads with a, b values in the range 0---100 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
258 |
\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
|
259 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
260 |
\begin{frame}{Problem 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
|
261 |
Write a program that generates a list of all four digit numbers that have all their digits even and are perfect squares.\\For example, the output should include 6400 but not 8100 (one digit is odd) or 4248 (not a perfect square). |
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{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
263 |
|
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{frame}{Problem 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
|
265 |
The aliquot of a number is defined as: the sum of the \emph{proper} divisors of the number. For example, the aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16.\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
266 |
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
|
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}{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
|
270 |
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
|
271 |
Example: \texttt{220, 284}\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
272 |
Write a program that prints all five digit amicable pairs. |
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
273 |
\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
|
274 |
\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
|
275 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
276 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
277 |
% 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
|
278 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
279 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
280 |
\subsection{Lists} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
281 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
282 |
\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
|
283 |
\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
|
284 |
\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
|
285 |
>>> 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
|
286 |
>>> 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
|
287 |
>>> 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
|
288 |
4 |
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[0] + a[1] + a[2] + a[-1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
290 |
10 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
291 |
\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
|
292 |
\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
|
293 |
\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
|
294 |
\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
|
295 |
\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
|
296 |
\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
|
297 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
298 |
\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
|
299 |
\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
|
300 |
\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
|
301 |
\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
|
302 |
\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
|
303 |
\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
|
304 |
\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
|
305 |
\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
|
306 |
>>> 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
|
307 |
[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
|
308 |
>>> a[1:-1] |
15
1bc961ae4ddd
Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
309 |
[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
|
310 |
>>> 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
|
311 |
False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
312 |
\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
|
313 |
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
|
314 |
\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
|
315 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
316 |
\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
|
317 |
\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
|
318 |
\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
|
319 |
>>> 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
|
320 |
[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
|
321 |
>>> 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
|
322 |
[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
|
323 |
>>> 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
|
324 |
\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
|
325 |
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
|
326 |
\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
|
327 |
\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
|
328 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
329 |
\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
|
330 |
\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
|
331 |
\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
|
332 |
>>> 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
|
333 |
>>> a[:2] |
15
1bc961ae4ddd
Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
334 |
[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
|
335 |
>>> 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
|
336 |
[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
|
337 |
\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
|
338 |
\pause |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
339 |
\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
|
340 |
\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
|
341 |
>>> 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
|
342 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
343 |
[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
|
344 |
\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
|
345 |
\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
|
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 |
\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
|
348 |
\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
|
349 |
\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
|
350 |
>>> 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
|
351 |
>>> 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
|
352 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
353 |
['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
|
354 |
>>> 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
|
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 |
[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
|
357 |
>>> 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
|
358 |
>>> 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
|
359 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
360 |
[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
|
361 |
\end{lstlisting} |
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
362 |
\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
|
363 |
\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
|
364 |
|
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
365 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
366 |
% TIME: 10 m, running 65m |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
367 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
368 |
|
5
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
369 |
\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
|
370 |
\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
|
371 |
\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
|
372 |
>>> 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
|
373 |
>>> 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
|
374 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
375 |
[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
|
376 |
>>> 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
|
377 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
378 |
[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
|
379 |
>>> 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
|
380 |
>>> 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
|
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', ['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
|
383 |
\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
|
384 |
\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
|
385 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
386 |
\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
|
387 |
\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
|
388 |
\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
|
389 |
>>> 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
|
390 |
>>> '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
|
391 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
392 |
>>> '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
|
393 |
False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
394 |
>>> '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
|
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 |
>>> '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
|
397 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
398 |
\end{lstlisting} |
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
399 |
\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
|
400 |
\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
|
401 |
|
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
402 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
403 |
% TIME: 5 m, running 70m |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
404 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
405 |
|
5
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
406 |
\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
|
407 |
\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
|
408 |
\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
|
409 |
>>> 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
|
410 |
>>> 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
|
411 |
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
|
412 |
>>> 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
|
413 |
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
|
414 |
File "<stdin>", line 1, in ? |
15
1bc961ae4ddd
Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
415 |
TypeError: object does not support 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
|
416 |
\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
|
417 |
\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
|
418 |
\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
|
419 |
\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
|
420 |
\end{itemize} |
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
421 |
\inctime{5} |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
422 |
\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
|
423 |
|
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
424 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
425 |
% TIME: 5 m, running 75m |
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
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 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
428 |
\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
|
429 |
\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
|
430 |
\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
|
431 |
>>> 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
|
432 |
[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
|
433 |
>>> 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
|
434 |
[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
|
435 |
>>> 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
|
436 |
[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
|
437 |
>>> 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
|
438 |
[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
|
439 |
>>> 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
|
440 |
[] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
441 |
\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
|
442 |
\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
|
443 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
444 |
\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
|
445 |
\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
|
446 |
\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
|
447 |
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
|
448 |
....: 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
|
449 |
....: |
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 |
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
|
452 |
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
|
453 |
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
|
454 |
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
|
455 |
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
|
456 |
\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
|
457 |
\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
|
458 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
459 |
\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
|
460 |
\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
|
461 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
462 |
\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
|
463 |
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
|
464 |
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
|
465 |
....: 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
|
466 |
....: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
\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
|
471 |
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
|
472 |
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
|
473 |
\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
|
474 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
475 |
\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
|
476 |
\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
|
477 |
\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
|
478 |
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
|
479 |
....: 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
|
480 |
....: |
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 |
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
|
483 |
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
|
484 |
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
|
485 |
\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
|
486 |
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
|
487 |
\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
|
488 |
\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
|
489 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
490 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
21
844b81ad2a3c
Added inctime to Day-1 Session 2 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
18
diff
changeset
|
491 |
% 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
|
492 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
493 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
494 |
\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
|
495 |
\frametitle{What did we learn?} |
5
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
496 |
\tableofcontents |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
497 |
% You might wish to add the option [pausesections] |
15
1bc961ae4ddd
Completed reworking and refactoring on Session 2 for BPRIM.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
14
diff
changeset
|
498 |
\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
|
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 |
\end{document} |