equal
deleted
inserted
replaced
112 \begin{frame} |
112 \begin{frame} |
113 {Acknowledgements} |
113 {Acknowledgements} |
114 \begin{center} |
114 \begin{center} |
115 This program is conducted by\\ |
115 This program is conducted by\\ |
116 IIT, Bombay\\ |
116 IIT, Bombay\\ |
117 through CDEEP\\as part of the open source initiatives\\ |
117 as part of the open source initiatives\\ |
118 under the aegis of\\ |
118 under the aegis of\\ |
119 \alert{National Mission on Education through ICT,} \\ |
119 \alert{National Mission on Education through ICT,} \\ |
120 Ministry of HRD. |
120 Ministry of HRD. |
121 \end{center} |
121 \end{center} |
122 \end{frame} |
122 \end{frame} |
260 |
260 |
261 \section{Python} |
261 \section{Python} |
262 |
262 |
263 \subsection{Getting Started} |
263 \subsection{Getting Started} |
264 |
264 |
265 \begin{frame}[fragile]{At the prompt, type the following} |
265 \begin{frame}[fragile] |
|
266 \frametitle{At the prompt, type the following} |
266 \begin{lstlisting} |
267 \begin{lstlisting} |
267 >>> print 'Hello Python' |
268 >>> print 'Hello Python' |
268 >>> print 3124 * 126789 |
269 >>> print 3124 * 126789 |
269 >>> 1786 % 12 |
270 >>> 1786 % 12 |
270 >>> 3124 * 126789 |
271 >>> 3124 * 126789 |
273 >>> verybig = big * big * big * big |
274 >>> verybig = big * big * big * big |
274 >>> 12345**6, 12345**67, 12345**678 |
275 >>> 12345**6, 12345**67, 12345**678 |
275 \end{lstlisting} |
276 \end{lstlisting} |
276 \end{frame} |
277 \end{frame} |
277 |
278 |
278 \begin{frame}[fragile]{At the prompt, type the following} |
279 \begin{frame}[fragile] |
|
280 \frametitle{At the prompt, type the following} |
279 \begin{lstlisting} |
281 \begin{lstlisting} |
280 >>> s = 'Hello ' |
282 >>> s = 'Hello ' |
281 >>> p = 'World' |
283 >>> p = 'World' |
282 >>> s + p |
284 >>> s + p |
283 >>> s * 12 |
285 >>> s * 12 |
286 >>> s * 12 + p * 12 |
288 >>> s * 12 + p * 12 |
287 >>> 12 * s |
289 >>> 12 * s |
288 \end{lstlisting} |
290 \end{lstlisting} |
289 \end{frame} |
291 \end{frame} |
290 |
292 |
291 \begin{frame}[fragile]{At the prompt, type the following} |
293 \begin{frame}[fragile] |
|
294 \frametitle{At the prompt, type the following} |
292 \begin{lstlisting} |
295 \begin{lstlisting} |
293 >>> 17/2 |
296 >>> 17/2 |
294 >>> 17/2.0 |
297 >>> 17/2.0 |
295 >>> 17.0/2 |
298 >>> 17.0/2 |
296 >>> 17.0/8.5 |
299 >>> 17.0/8.5 |
302 \begin{block}{Mini exercise} |
305 \begin{block}{Mini exercise} |
303 Round a float to the nearest integer, using \texttt{int()}? |
306 Round a float to the nearest integer, using \texttt{int()}? |
304 \end{block} |
307 \end{block} |
305 \end{frame} |
308 \end{frame} |
306 |
309 |
307 \begin{frame}{Midi exercises} |
310 \begin{frame}\frametitle{Midi exercises} |
308 \begin{center} |
311 \begin{center} |
309 \begin{itemize} |
312 \begin{itemize} |
310 \item What does this do? |
313 \item What does this do? |
311 \item \texttt{round(amount * 10) /10.0 } |
314 \item \texttt{round(amount * 10) /10.0 } |
312 \end{itemize} |
315 \end{itemize} |
313 \end{center} |
316 \end{center} |
314 \end{frame} |
317 \end{frame} |
315 |
318 |
316 \begin{frame}{More exercises} |
319 \begin{frame}\frametitle{More exercises} |
317 \begin{center} |
320 \begin{center} |
318 \begin{block}{Round sums} |
321 \begin{block}{Round sums} |
319 How to round a number to the nearest 5 paise?\\ |
322 How to round a number to the nearest 5 paise?\\ |
320 \begin{description} |
323 \begin{description} |
321 \item[Remember] 17.23 $\rightarrow$ 17.25,\\ while 17.22 $\rightarrow$ 17.20\\ |
324 \item[Remember] 17.23 $\rightarrow$ 17.25,\\ while 17.22 $\rightarrow$ 17.20\\ |
323 How to round a number to the nearest 20 paise? |
326 How to round a number to the nearest 20 paise? |
324 \end{block} |
327 \end{block} |
325 \end{center} |
328 \end{center} |
326 \end{frame} |
329 \end{frame} |
327 |
330 |
328 \begin{frame}[fragile] {A question of good style} |
331 \begin{frame}[fragile] \frametitle{A question of good style} |
329 \begin{lstlisting} |
332 \begin{lstlisting} |
330 amount = 12.68 |
333 amount = 12.68 |
331 denom = 0.05 |
334 denom = 0.05 |
332 nCoins = round(amount/denom) |
335 nCoins = round(amount/denom) |
333 rAmount = nCoins * denom |
336 rAmount = nCoins * denom |
496 In [5]: a.upper().lower() |
499 In [5]: a.upper().lower() |
497 Out[5]: 'hello world' |
500 Out[5]: 'hello world' |
498 \end{lstlisting} |
501 \end{lstlisting} |
499 \end{frame} |
502 \end{frame} |
500 |
503 |
501 \begin{frame}[fragile]{Still with strings} |
504 \begin{frame}[fragile]\frametitle{Still with strings} |
502 \begin{lstlisting} |
505 \begin{lstlisting} |
503 In [6]: a.split() |
506 In [6]: a.split() |
504 Out[6]: ['hello', 'world'] |
507 Out[6]: ['hello', 'world'] |
505 In [7]: ''.join(['a', 'b', 'c']) |
508 In [7]: ''.join(['a', 'b', 'c']) |
506 Out[7]: 'abc' |
509 Out[7]: 'abc' |
511 \texttt{a.split( 'o' )}\\ |
514 \texttt{a.split( 'o' )}\\ |
512 \texttt{'x'.join( a.split( 'o' ) )} |
515 \texttt{'x'.join( a.split( 'o' ) )} |
513 \end{block} |
516 \end{block} |
514 \end{frame} |
517 \end{frame} |
515 |
518 |
516 \begin{frame}[fragile]{String formatting} |
519 \begin{frame}[fragile]\frametitle{String formatting} |
517 \begin{lstlisting} |
520 \begin{lstlisting} |
518 In [11]: x, y = 1, 1.2 |
521 In [11]: x, y = 1, 1.2 |
519 In [12]: 'x is %s, y is %s' %(x, y) |
522 In [12]: 'x is %s, y is %s' %(x, y) |
520 Out[12]: 'x is 1, y is 1.234' |
523 Out[12]: 'x is 1, y is 1.234' |
521 \end{lstlisting} |
524 \end{lstlisting} |