day2/session2.tex
changeset 373 f04eca8b2f3d
parent 344 19754ed6050f
child 378 2299700a8b97
equal deleted inserted replaced
372:5f02dfb93df1 373:f04eca8b2f3d
    76 \title[Basic Python]{Python language: Data structures and functions}
    76 \title[Basic Python]{Python language: Data structures and functions}
    77 
    77 
    78 \author[FOSSEE Team] {The FOSSEE Group}
    78 \author[FOSSEE Team] {The FOSSEE Group}
    79 
    79 
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    81 \date[] {12 January, 2010\\Day 2, Session 2}
    81 \date[] {13 February, 2010\\Day 3, Session 1}
    82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    83 
    83 
    84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
    84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
    85 %\logo{\pgfuseimage{iitmlogo}}
    85 %\logo{\pgfuseimage{iitmlogo}}
    86 
    86 
   206   \item If the number is even, divide by 2; if the number is odd, multiply by 3 and add 1.
   206   \item If the number is even, divide by 2; if the number is odd, multiply by 3 and add 1.
   207   \item Repeat the procedure with the new number.
   207   \item Repeat the procedure with the new number.
   208   \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops.
   208   \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops.
   209 \end{enumerate}
   209 \end{enumerate}
   210     Write a program that accepts the starting value and prints out the Collatz sequence.
   210     Write a program that accepts the starting value and prints out the Collatz sequence.
   211 \end{frame}
       
   212 
       
   213 \begin{frame}[fragile]{Problem 1.3}
       
   214   Write a program that prints the following pyramid on the screen. 
       
   215   \begin{lstlisting}
       
   216 1
       
   217 2  2
       
   218 3  3  3
       
   219 4  4  4  4
       
   220   \end{lstlisting}
       
   221 The number of lines must be obtained from the user.\\
       
   222 \pause
       
   223 \emphbar{When can your code fail?}
       
   224 \inctime{5}
   211 \inctime{5}
   225 \end{frame}
   212 \end{frame}
   226 
   213 
   227 \section{Data structures}
   214 \section{Data structures}
   228 \subsection{Lists}
   215 \subsection{Lists}
   516     while i * i < n:
   503     while i * i < n:
   517         i += 1
   504         i += 1
   518     return i * i == n, i
   505     return i * i == n, i
   519   \end{lstlisting}
   506   \end{lstlisting}
   520 \end{frame}
   507 \end{frame}
       
   508 
       
   509 \begin{frame}[fragile]
       
   510   \frametitle {What does this function do?}
       
   511   \begin{lstlisting}
       
   512 def what( x, n ):
       
   513     if n < 0: 
       
   514        n = -n
       
   515        x = 1.0 / x
       
   516 
       
   517     z = 1.0
       
   518     while n > 0:
       
   519         if n % 2 == 1:
       
   520             z *= x
       
   521         x *= x
       
   522         n /= 2
       
   523     return z
       
   524   \end{lstlisting}
       
   525 \end{frame} 
   521 
   526 
   522 \begin{frame}
   527 \begin{frame}
   523   \frametitle{What did we learn?}
   528   \frametitle{What did we learn?}
   524   \begin{itemize}
   529   \begin{itemize}
   525     \item Loops: \kwrd{while}, \kwrd{for}
   530     \item Loops: \kwrd{while}, \kwrd{for}