day1/Session-2.tex
changeset 21 844b81ad2a3c
parent 18 2a70a7ef7e62
child 46 63704b5650f1
equal deleted inserted replaced
20:84458ebb6951 21:844b81ad2a3c
   247       \item \typ{abs, any, all, len, max, min}
   247       \item \typ{abs, any, all, len, max, min}
   248       \item \typ{pow, range, sum, type}
   248       \item \typ{pow, range, sum, type}
   249       \item Refer here:
   249       \item Refer here:
   250           \url{http://docs.python.org/library/functions.html}
   250           \url{http://docs.python.org/library/functions.html}
   251   \end{itemize}
   251   \end{itemize}
   252   \inctime{15} 
   252   \inctime{10} 
   253 \end{frame}
   253 \end{frame}
   254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   255 % TIME: 15 m, running 120m 
   255 % TIME: 10 m, running 30m 
   256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   257 
   257 
   258 \begin{frame}{Problem set 2}
   258 \begin{frame}{Problem set 2}
   259   The focus is on writing functions and calling them.
   259   The focus is on writing functions and calling them.
   260 \end{frame}
   260 \end{frame}
   279 
   279 
   280 \begin{frame}{Problem 2.5}
   280 \begin{frame}{Problem 2.5}
   281   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.\\
   281   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.\\
   282   Example: \texttt{220, 284}\\
   282   Example: \texttt{220, 284}\\
   283   Write a program that prints all five digit amicable pairs.
   283   Write a program that prints all five digit amicable pairs.
   284   \inctime{30}
   284   \inctime{25}
   285 \end{frame}
   285 \end{frame}
   286 
   286 
   287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   288 % TIME: 30 m, running 150m 
   288 % TIME: 25 m, running 55m 
   289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   290 
   290 
   291 \subsection{Lists}
   291 \subsection{Lists}
   292 
   292 
   293 \begin{frame}[fragile]
   293 \begin{frame}[fragile]
   368 >>> a[0:2] = [] # Remove items
   368 >>> a[0:2] = [] # Remove items
   369 >>> a.append( 12345 )
   369 >>> a.append( 12345 )
   370 >>> a
   370 >>> a
   371 [123, 1234, 12345]
   371 [123, 1234, 12345]
   372 \end{lstlisting}
   372 \end{lstlisting}
   373 \end{frame}
   373 \inctime{10}
       
   374 \end{frame}
       
   375 
       
   376 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   377 % TIME: 10 m, running 65m 
       
   378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   374 
   379 
   375 \begin{frame}[fragile]
   380 \begin{frame}[fragile]
   376   \frametitle{List methods}
   381   \frametitle{List methods}
   377 \begin{lstlisting}
   382 \begin{lstlisting}
   378 >>> a = ['spam', 'eggs', 1, 12]
   383 >>> a = ['spam', 'eggs', 1, 12]
   400 >>> 'snake' not in a
   405 >>> 'snake' not in a
   401 True
   406 True
   402 >>> 'ell' in 'hello world'
   407 >>> 'ell' in 'hello world'
   403 True
   408 True
   404   \end{lstlisting}
   409   \end{lstlisting}
   405 \end{frame}
   410   \inctime{5}
       
   411 \end{frame}
       
   412 
       
   413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   414 % TIME: 5 m, running 70m 
       
   415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   406 
   416 
   407 \begin{frame}[fragile]
   417 \begin{frame}[fragile]
   408   \frametitle{Tuples: immutable}
   418   \frametitle{Tuples: immutable}
   409 \begin{lstlisting}
   419 \begin{lstlisting}
   410 >>> t = (0, 1, 2)
   420 >>> t = (0, 1, 2)
   417 \end{lstlisting}  
   427 \end{lstlisting}  
   418 \begin{itemize}
   428 \begin{itemize}
   419     \item Multiple return values are actually a tuple.
   429     \item Multiple return values are actually a tuple.
   420     \item Exchange is tuple (un)packing
   430     \item Exchange is tuple (un)packing
   421 \end{itemize}
   431 \end{itemize}
   422 
   432 \inctime{5}
   423 \end{frame}
   433 \end{frame}
       
   434 
       
   435 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   436 % TIME: 5 m, running 75m 
       
   437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   424 
   438 
   425 \begin{frame}[fragile]
   439 \begin{frame}[fragile]
   426   \frametitle{\typ{range()} function}
   440   \frametitle{\typ{range()} function}
   427   \begin{lstlisting}
   441   \begin{lstlisting}
   428 >>> range(7)
   442 >>> range(7)
   479 0 a
   493 0 a
   480 1 b
   494 1 b
   481 2 c
   495 2 c
   482   \end{lstlisting}
   496   \end{lstlisting}
   483 Try: \typ{print enumerate(a)}
   497 Try: \typ{print enumerate(a)}
   484 \inctime{20}
   498 \inctime{10}
   485 \end{frame}
   499 \end{frame}
   486 
   500 
   487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   501 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   488 % TIME: 20 m, running 170m 
   502 % TIME: 10 m, running 85m 
   489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   503 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   490 
   504 
   491 \begin{frame}
   505 \begin{frame}
   492   \frametitle{Did we meet the goal?}
   506   \frametitle{Did we meet the goal?}
   493   \tableofcontents
   507   \tableofcontents