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 |
84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
85 %\logo{\pgfuseimage{iitmlogo}} |
85 %\logo{\pgfuseimage{iitmlogo}} |
86 |
86 |
87 |
87 |
88 %% Delete this, if you do not want the table of contents to pop up at |
88 %% Delete this, if you do not want the table of contents to pop up at |
89 %% the beginning of each subsection: |
89 %% the beginning of each section: |
90 \AtBeginSubsection[] |
90 \AtBeginSection[] |
91 { |
91 { |
92 \begin{frame}<beamer> |
92 \begin{frame}<beamer> |
93 \frametitle{Outline} |
93 \frametitle{Outline} |
94 \tableofcontents[currentsection,currentsubsection] |
94 \tableofcontents[currentsection] |
95 \end{frame} |
95 \end{frame} |
96 } |
96 } |
97 |
97 |
98 |
98 |
99 % If you wish to uncover everything in a step-wise fashion, uncomment |
99 % If you wish to uncover everything in a step-wise fashion, uncomment |
147 3.0 , 3.5, 4.0 , 4.5, 5.0 ] |
139 3.0 , 3.5, 4.0 , 4.5, 5.0 ] |
148 \end{lstlisting} |
140 \end{lstlisting} |
149 \end{frame} |
141 \end{frame} |
150 |
142 |
151 \begin{frame}[fragile] |
143 \begin{frame}[fragile] |
152 \frametitle{Problem 3.4a (optional)} |
144 \frametitle{Problem 3.4a} |
153 |
145 |
154 Use the \typ{linspace} function and generate a list of N tuples of the form\\ |
146 Use the \typ{linspace} function and generate a list of N tuples of the form\\ |
155 \typ{[($x_1$,f($x_1$)),($x_2$,f($x_2$)),\ldots,($x_N$,f($x_N$))]}\\for the following functions,\begin{itemize} |
147 \typ{[($x_1$,f($x_1$)),($x_2$,f($x_2$)),\ldots,($x_N$,f($x_N$))]}\\for the following functions,\begin{itemize} |
156 \item \typ{f(x) = sin(x)} |
148 \item \typ{f(x) = sin(x)} |
157 \item \typ{f(x) = sin(x) + sin(10*x)}. |
149 \item \typ{f(x) = sin(x) + sin(10*x)}. |
158 \end{itemize} |
150 \end{itemize} |
159 \end{frame} |
151 \end{frame} |
160 |
152 |
161 \begin{frame}[fragile] |
153 \begin{frame}[fragile] |
162 \frametitle{Problem 3.4b (optional)} |
154 \frametitle{Problem 3.4b} |
163 |
155 |
164 Using the tuples generated earlier, determine the intervals where the roots of the functions lie. |
156 Using the tuples generated earlier, determine the intervals where the roots of the functions lie. |
165 |
157 |
166 \inctime{15} |
158 \inctime{15} |
167 \end{frame} |
159 \end{frame} |
168 |
160 |
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
170 % TIME: 15 m, running 185m |
162 % TIME: 15 m, running 185m |
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
172 |
164 |
173 \subsection{IO} |
165 \section{Input/Output} |
174 |
166 |
175 \begin{frame}[fragile] |
167 \begin{frame}[fragile] |
176 \frametitle{Simple tokenizing and parsing} |
168 \frametitle{Simple tokenizing and parsing} |
177 \begin{lstlisting} |
169 \begin{lstlisting} |
178 s = """The quick brown fox jumped |
170 s = """The quick brown fox jumped |
345 Put all the functions you have written so far as part of the problems |
337 Put all the functions you have written so far as part of the problems |
346 into one module called \typ{bprim.py} and use this module from IPython. |
338 into one module called \typ{bprim.py} and use this module from IPython. |
347 |
339 |
348 \inctime{25} |
340 \inctime{25} |
349 \end{frame} |
341 \end{frame} |
|
342 |
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
351 % TIME: 25 m, running 230m |
344 % TIME: 25 m, running 230m |
352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
353 |
346 |
354 \subsection{Coding Style in Python} |
347 \section{Coding Style in Python} |
355 \begin{frame}{Readability and Consistency} |
348 \begin{frame}{Readability and Consistency} |
356 \begin{itemize} |
349 \begin{itemize} |
357 \item Readability Counts!-Code is read more often than its written. |
350 \item Readability Counts!-Code is read more often than its written. |
358 \item Consistency! |
351 \item Consistency! |
359 \item Know when to be inconsistent. |
352 \item Know when to be inconsistent. |
394 \item One liner docstrings |
387 \item One liner docstrings |
395 \end{itemize} |
388 \end{itemize} |
396 \inctime{10} |
389 \inctime{10} |
397 \end{frame} |
390 \end{frame} |
398 |
391 |
399 |
392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
400 \subsection{Objects} |
393 % TIME: 10 m, running 240m |
|
394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
395 |
|
396 \section{Objects} |
401 \begin{frame}{Objects in Python} |
397 \begin{frame}{Objects in Python} |
402 \begin{itemize} |
398 \begin{itemize} |
403 \item What is an Object? (Types and classes) |
399 \item What is an Object? (Types and classes) |
404 \item identity |
400 \item identity |
405 \item type |
401 \item type |
406 \item method |
402 \item method |
407 \end{itemize} |
403 \end{itemize} |
408 \end{frame} |
404 \end{frame} |
409 |
405 |
410 \begin{frame}[fragile] |
406 \begin{frame}{Everything is an Object!} |
411 \frametitle{Why are they useful?} |
407 \begin{itemize} |
|
408 \item \typ{list, tuple} |
|
409 \item \typ{string, dictionary} |
|
410 \item \typ{function} |
|
411 \item Of course, user defined class objects! |
|
412 \end{itemize} |
|
413 \end {frame} |
|
414 |
|
415 \begin{frame}{Using Objects} |
|
416 \begin{itemize} |
|
417 \item Creating Objects: Initialization |
|
418 \item Object Manipulation: Object methods and ``.'' operator |
|
419 \end{itemize} |
|
420 \end{frame} |
|
421 |
|
422 \begin{frame}[fragile] |
|
423 \frametitle{IPython Examples} |
|
424 \begin{lstlisting} |
|
425 In [1]: l = [] #Initialising a list object |
|
426 In [2]: l? |
|
427 In [3]: l.<tab> |
|
428 \end{lstlisting} |
|
429 \end{frame} |
|
430 |
|
431 \begin{frame}[fragile] |
|
432 \frametitle{Objects provide a certain consistency} |
412 \small |
433 \small |
413 \begin{lstlisting} |
434 \begin{lstlisting} |
414 for element in (1, 2, 3): |
435 for element in (1, 2, 3): |
415 print element |
436 print element |
416 for key in {'one':1, 'two':2}: |
437 for key in {'one':1, 'two':2}: |
428 All objects providing a similar inteface can be used the same way.\\ |
449 All objects providing a similar inteface can be used the same way.\\ |
429 Functions (and others) are first-class objects. Can be passed to and returned from functions. |
450 Functions (and others) are first-class objects. Can be passed to and returned from functions. |
430 \inctime{10} |
451 \inctime{10} |
431 \end{frame} |
452 \end{frame} |
432 |
453 |
433 \begin{frame} |
454 \section{Summary} |
434 \frametitle{What did we learn?} |
455 |
435 \tableofcontents |
456 \begin{frame}{What have we learnt so far?} |
436 % You might wish to add the option [pausesections] |
457 \begin{itemize} |
437 \end{frame} |
458 \item Writing to and Reading from files using \typ{for} |
|
459 \item Using and writing Python Modules |
|
460 \item Coding Style |
|
461 \item Objects in Python |
|
462 \end{itemize} |
|
463 \end{frame} |
|
464 |
438 \end{document} |
465 \end{document} |