1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 % Tutorial slides on Python. |
2 %Tutorial slides on Python. |
3 % |
3 % |
4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in> |
4 % Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in> |
5 % Copyright (c) 2005-2009, Prabhu Ramachandran |
5 % Copyright (c) 2005-2009, Prabhu Ramachandran |
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
7 |
7 |
31 |
31 |
32 \definecolor{darkgreen}{rgb}{0,0.5,0} |
32 \definecolor{darkgreen}{rgb}{0,0.5,0} |
33 |
33 |
34 \usepackage{listings} |
34 \usepackage{listings} |
35 \lstset{language=Python, |
35 \lstset{language=Python, |
36 basicstyle=\ttfamily, |
36 basicstyle=\ttfamily\bfseries, |
37 commentstyle=\color{red}\itshape, |
37 commentstyle=\color{red}\itshape, |
38 stringstyle=\color{darkgreen}, |
38 stringstyle=\color{darkgreen}, |
39 showstringspaces=false, |
39 showstringspaces=false, |
40 keywordstyle=\color{blue}\bfseries} |
40 keywordstyle=\color{blue}\bfseries} |
41 |
41 |
132 % |
132 % |
133 % * Add slide on Python packages (modules) |
133 % * Add slide on Python packages (modules) |
134 % * Add slides on reference counting. |
134 % * Add slides on reference counting. |
135 |
135 |
136 \section{Agenda} |
136 \section{Agenda} |
137 \begin{frame}{About the Workshop} |
137 \begin{frame}{About the Workshop, Day 1} |
138 \begin{description} |
138 \begin{description} |
139 \item[Day 1, Session 1] Sat 09:30--11:00 |
139 \item[Day 1, Session 1] Sat 09:30--11:00 |
140 \item[Day 1, Session 2] Sat 11:15--12:45 |
140 \item[Day 1, Session 2] Sat 11:15--12:45 |
141 \item[Day 1, Session 3] Sat 13:45--15:15 |
141 \item[Day 1, Session 3] Sat 13:45--15:15 |
142 \item[Day 1, Session 4] Sat 15:30--17:00 |
142 \item[Day 1, Session 4] Sat 15:30--17:00 |
|
143 \end{description} |
|
144 \end{frame} |
|
145 \begin{frame}{About the Workshop, Day 2} |
|
146 \begin{description} |
143 \item[Day 2, Quiz] Sun 09:00--09:30 |
147 \item[Day 2, Quiz] Sun 09:00--09:30 |
144 \item[Day 2, Session 1] Sun 09:30--11:00 |
148 \item[Day 2, Session 1] Sun 09:30--11:00 |
145 \item[Day 2, Session 2] Sun 11:15--12:45 |
149 \item[Day 2, Session 2] Sun 11:15--12:45 |
146 \item[Day 2, Session 3] Sun 13:45--15:15 |
150 \item[Day 2, Session 3] Sun 13:45--15:15 |
147 \item[Day 2, Session 4] Sun 15:30--17:00 |
151 \item[Day 2, Session 4] Sun 15:30--17:00 |
149 \end{frame} |
153 \end{frame} |
150 |
154 |
151 \begin{frame}{About the Workshop} |
155 \begin{frame}{About the Workshop} |
152 \begin{block}{Intended Audience} |
156 \begin{block}{Intended Audience} |
153 \begin{itemize} |
157 \begin{itemize} |
154 \item Aimed at Engg., Mathematics and Science teachers. |
158 \item Engg., Mathematics and Science teachers. |
155 \item Interested students from similar streams. |
159 \item Interested students from similar streams. |
156 \end{itemize} |
160 \end{itemize} |
157 \end{block} |
161 \end{block} |
158 |
162 |
159 \begin{block}{Goal} |
163 \begin{block}{Goal:} |
160 Successful participants will be able to use python as their scripting and problem solving language. |
164 Successful participants will be able to |
|
165 \begin{itemize} |
|
166 \item use Python as their scripting and problem solving language. |
|
167 \item train the students to use Python for the same |
|
168 \end{itemize} |
161 \end{block} |
169 \end{block} |
162 \end{frame} |
170 \end{frame} |
163 |
171 |
164 \begin{frame}{Checklist} |
172 \begin{frame}{Checklist} |
165 \begin {block}{Live Python} |
173 \begin{block}{python} |
166 Have you booted using the Live Python DVD? |
|
167 \end {block} |
|
168 \begin{block}{python} |
|
169 Type python at the command line. Do you see version 2.5 or later? |
174 Type python at the command line. Do you see version 2.5 or later? |
170 \end{block} |
175 \end{block} |
171 \begin{block}{IPython} |
176 \begin{block}{IPython} |
172 Type ipython at the command line. Is it available? |
177 Type ipython at the command line. Is it available? |
173 \end{block} |
178 \end{block} |
306 \item \texttt{round(amount * 10) /10.0 } |
311 \item \texttt{round(amount * 10) /10.0 } |
307 \end{itemize} |
312 \end{itemize} |
308 \end{center} |
313 \end{center} |
309 \end{frame} |
314 \end{frame} |
310 |
315 |
311 \begin{frame}{More exercises?} |
316 \begin{frame}{More exercises} |
312 \begin{center} |
317 \begin{center} |
313 \begin{block}{Round sums} |
318 \begin{block}{Round sums} |
314 How to round a number to the nearest 5 paise?\\ |
319 How to round a number to the nearest 5 paise?\\ |
315 \begin{description} |
320 \begin{description} |
316 \item[Remember] 17.23 $\rightarrow$ 17.25,\\ while 17.22 $\rightarrow$ 17.20\\ |
321 \item[Remember] 17.23 $\rightarrow$ 17.25,\\ while 17.22 $\rightarrow$ 17.20\\ |
506 \texttt{a.split( 'o' )}\\ |
511 \texttt{a.split( 'o' )}\\ |
507 \texttt{'x'.join( a.split( 'o' ) )} |
512 \texttt{'x'.join( a.split( 'o' ) )} |
508 \end{block} |
513 \end{block} |
509 \end{frame} |
514 \end{frame} |
510 |
515 |
511 \begin{frame}[fragile]{Surprise! strings!!} |
516 \begin{frame}[fragile]{String formatting} |
512 \begin{lstlisting} |
517 \begin{lstlisting} |
513 In [11]: x, y = 1, 1.2 |
518 In [11]: x, y = 1, 1.2 |
514 In [12]: 'x is %s, y is %s' %(x, y) |
519 In [12]: 'x is %s, y is %s' %(x, y) |
515 Out[12]: 'x is 1, y is 1.234' |
520 Out[12]: 'x is 1, y is 1.234' |
516 \end{lstlisting} |
521 \end{lstlisting} |
566 \begin{frame} |
576 \begin{frame} |
567 {Creating python files} |
577 {Creating python files} |
568 \begin{itemize} |
578 \begin{itemize} |
569 \item aka scripts |
579 \item aka scripts |
570 \item use your editor |
580 \item use your editor |
571 \item Note that white space is the way to specify blocks! |
|
572 \item extension \typ{.py} |
581 \item extension \typ{.py} |
573 \item run with \texttt{python hello.py} at the command line |
582 \item run with \texttt{python hello.py} at the command line |
574 \item in IPython\ldots |
583 \item in IPython using \kwrd{\%run} |
575 \end{itemize} |
584 \end{itemize} |
576 \end{frame} |
585 \end{frame} |
577 |
586 |
578 \begin{frame}[fragile] |
587 \begin{frame}[fragile] |
579 \frametitle{\typ{If...elif...else} example} |
588 \frametitle{\typ{If...elif...else} example} |
625 |
634 |
626 \section{Session Summary} |
635 \section{Session Summary} |
627 \begin{frame}{So what have we learnt so far?} |
636 \begin{frame}{So what have we learnt so far?} |
628 \begin{itemize} |
637 \begin{itemize} |
629 \item The interactive interpreter |
638 \item The interactive interpreter |
630 \item Basic Data Types-Numbers |
639 \item Basic Data Types |
631 \item \typ{if/elif/else, while} |
640 \item Creating and running a Python script |
|
641 \item \kwrd{if/elif/else} |
632 \item Simple IO |
642 \item Simple IO |
633 \item Creating and running a Python script |
643 \item Basic Looping with \kwrd{while} |
634 \end{itemize} |
644 \end{itemize} |
635 \end{frame} |
645 \end{frame} |
636 \end{document} |
646 \end{document} |