equal
deleted
inserted
replaced
109 \begin{frame} |
109 \begin{frame} |
110 \titlepage |
110 \titlepage |
111 \end{frame} |
111 \end{frame} |
112 |
112 |
113 \section{Python} |
113 \section{Python} |
|
114 |
114 \subsection{Exercises on Control flow} |
115 \subsection{Exercises on Control flow} |
115 \begin{frame} |
116 \begin{frame} |
116 \frametitle{Problem set 1} |
117 \frametitle{Problem set 1} |
117 \begin{itemize} |
118 \begin{itemize} |
118 \item All the problems can be\\ |
119 \item All the problems can be\\ |
126 \end{frame} |
127 \end{frame} |
127 |
128 |
128 \begin{frame}{Problem 1.2 - Collatz sequence} |
129 \begin{frame}{Problem 1.2 - Collatz sequence} |
129 \begin{enumerate} |
130 \begin{enumerate} |
130 \item Start with an arbitrary (positive) integer. |
131 \item Start with an arbitrary (positive) integer. |
131 \item If the number is even, divide by 2; if the number is odd multiply by 3 and add 1. |
132 \item If the number is even, divide by 2; if the number is odd, multiply by 3 and add 1. |
132 \item Repeat the procedure with the new number. |
133 \item Repeat the procedure with the new number. |
133 \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops. |
134 \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops. |
134 \end{enumerate} |
135 \end{enumerate} |
135 Write a program that accepts the starting value and prints out the Collatz sequence. |
136 Write a program that accepts the starting value and prints out the Collatz sequence. |
136 |
137 |
156 4 4 4 4 |
157 4 4 4 4 |
157 \end{lstlisting} |
158 \end{lstlisting} |
158 The number of lines must be obtained from the user as input.\\ |
159 The number of lines must be obtained from the user as input.\\ |
159 \pause |
160 \pause |
160 When can your code fail? |
161 When can your code fail? |
161 \only<2->{\inctime{25}} |
162 \only<2->{\inctime{20}} |
162 \end{frame} |
163 \end{frame} |
163 |
164 |
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
165 % TIME: 25 m, running 105m |
166 % TIME: 20 m, running 20m |
166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
167 |
168 |
168 \subsection{Functions} |
169 \subsection{Functions} |
169 \begin{frame}[fragile] |
170 \begin{frame}[fragile] |
170 \frametitle{Functions: examples} |
171 \frametitle{Functions: examples} |
314 \end{itemize} |
315 \end{itemize} |
315 \begin{lstlisting} |
316 \begin{lstlisting} |
316 >>> a[1:3] # A slice. |
317 >>> a[1:3] # A slice. |
317 [2, 3] |
318 [2, 3] |
318 >>> a[1:-1] |
319 >>> a[1:-1] |
319 [2, 3, 4] |
320 [2, 3] |
320 >>> a[1:] == a[1:-1] |
321 >>> a[1:] == a[1:-1] |
321 False |
322 False |
322 \end{lstlisting} |
323 \end{lstlisting} |
323 Explain last result |
324 Explain last result |
324 \end{frame} |
325 \end{frame} |
339 \begin{frame}[fragile] |
340 \begin{frame}[fragile] |
340 \frametitle{List: examples} |
341 \frametitle{List: examples} |
341 \begin{lstlisting} |
342 \begin{lstlisting} |
342 >>> a = [1, 2, 3, 4] |
343 >>> a = [1, 2, 3, 4] |
343 >>> a[:2] |
344 >>> a[:2] |
344 [1, 3] |
345 [1, 2] |
345 >>> a[0:-1:2] |
346 >>> a[0:-1:2] |
346 [1, 3] |
347 [1, 3] |
347 \end{lstlisting} |
348 \end{lstlisting} |
348 \pause |
349 \pause |
349 \alert{Lists are mutable (unlike strings)} |
350 \alert{Lists are mutable (unlike strings)} |
376 \begin{lstlisting} |
377 \begin{lstlisting} |
377 >>> a = ['spam', 'eggs', 1, 12] |
378 >>> a = ['spam', 'eggs', 1, 12] |
378 >>> a.reverse() # in situ |
379 >>> a.reverse() # in situ |
379 >>> a |
380 >>> a |
380 [12, 1, 'eggs', 'spam'] |
381 [12, 1, 'eggs', 'spam'] |
381 >>> a.append(['x', 1]) |
382 >>> a.append(['x', 1]) |
382 >>> a |
383 >>> a |
383 [12, 1, 'eggs', 'spam', ['x', 1]] |
384 [12, 1, 'eggs', 'spam', ['x', 1]] |
384 >>> a.extend([1,2]) # Extend the list. |
385 >>> a.extend([1,2]) # Extend the list. |
385 >>> a.remove( 'spam' ) |
386 >>> a.remove( 'spam' ) |
386 >>> a |
387 >>> a |
410 >>> print t[0], t[1], t[2], t[-1] |
411 >>> print t[0], t[1], t[2], t[-1] |
411 0 1 2 2 |
412 0 1 2 2 |
412 >>> t[0] = 1 |
413 >>> t[0] = 1 |
413 Traceback (most recent call last): |
414 Traceback (most recent call last): |
414 File "<stdin>", line 1, in ? |
415 File "<stdin>", line 1, in ? |
415 TypeError: object does not support item |
416 TypeError: object does not support item assignment |
416 assignment |
|
417 \end{lstlisting} |
417 \end{lstlisting} |
418 \begin{itemize} |
418 \begin{itemize} |
419 \item Multiple return values are actually a tuple. |
419 \item Multiple return values are actually a tuple. |
420 \item Exchange is tuple (un)packing |
420 \item Exchange is tuple (un)packing |
421 \end{itemize} |
421 \end{itemize} |
490 |
490 |
491 \begin{frame} |
491 \begin{frame} |
492 \frametitle{Did we meet the goal?} |
492 \frametitle{Did we meet the goal?} |
493 \tableofcontents |
493 \tableofcontents |
494 % You might wish to add the option [pausesections] |
494 % You might wish to add the option [pausesections] |
495 \end{frame} |
495 \end{frame} |
496 |
496 |
497 \begin{frame} |
|
498 {Tomorrow} |
|
499 \begin{itemize} |
|
500 \item Plotting: 2D, 3D |
|
501 \item NumPy, SciPy |
|
502 \item Dictionary, Set |
|
503 \item Debugging |
|
504 \item Testing |
|
505 \item \ldots |
|
506 \end{itemize} |
|
507 11:30--13:00 Discussion of answers to problems OPTIONAL |
|
508 \end{frame} |
|
509 \end{document} |
497 \end{document} |