day2/session1.tex
changeset 227 a6705e2dfdc6
parent 217 2833f0b51adc
child 239 8953675dc056
equal deleted inserted replaced
218:0aa2964438c6 227:a6705e2dfdc6
   180 Out[3]: True
   180 Out[3]: True
   181 
   181 
   182 In [4]: f and t
   182 In [4]: f and t
   183 Out[4]: False
   183 Out[4]: False
   184   \end{lstlisting}
   184   \end{lstlisting}
       
   185   \inctime{5}
   185 \end{frame}
   186 \end{frame}
   186 
   187 
   187 \subsection{Strings}
   188 \subsection{Strings}
   188 
   189 
   189 \begin{frame}[fragile]
   190 \begin{frame}[fragile]
   250 In [1]: x, y = 1, 1.234
   251 In [1]: x, y = 1, 1.234
   251 
   252 
   252 In [2]: 'x is %s, y is %s' %(x, y)
   253 In [2]: 'x is %s, y is %s' %(x, y)
   253 Out[2]: 'x is 1, y is 1.234'
   254 Out[2]: 'x is 1, y is 1.234'
   254   \end{lstlisting}
   255   \end{lstlisting}
   255 \emphbar{
   256   \emphbar{\url{http://docs.python.org/library/stdtypes.html}}
   256 \url{http://docs.python.org/library/stdtypes.html}\\
   257   \inctime{10}
   257 }
       
   258 \inctime{10}
       
   259 \end{frame}
   258 \end{frame}
   260 
   259 
   261 \section{Operators}
   260 \section{Operators}
   262 \begin{frame}[fragile]
   261 \begin{frame}[fragile]
   263   \frametitle{Arithematic operators}
   262   \frametitle{Arithematic operators}
   336 Out[4]: True
   335 Out[4]: True
   337 
   336 
   338 In [5]: pos + neg != zer
   337 In [5]: pos + neg != zer
   339 Out[5]: False
   338 Out[5]: False
   340   \end{lstlisting}
   339   \end{lstlisting}
   341 \inctime{5}
       
   342 \end{frame}
   340 \end{frame}
   343 
   341 
   344 \begin{frame}[fragile]
   342 \begin{frame}[fragile]
   345   \frametitle{Built-ins}
   343   \frametitle{Built-ins}
   346   \begin{lstlisting}
   344   \begin{lstlisting}
   376       \end{lstlisting}
   374       \end{lstlisting}
   377   \end{itemize}
   375   \end{itemize}
   378   \inctime{15}
   376   \inctime{15}
   379 \end{frame}
   377 \end{frame}
   380 
   378 
   381 \begin{frame}[fragile] \frametitle{A question of good style}
       
   382   \begin{lstlisting}
       
   383     amount = 12.68
       
   384     denom = 0.05
       
   385     nCoins = round(amount/denom)
       
   386     rAmount = nCoins * denom
       
   387   \end{lstlisting}
       
   388   \pause
       
   389   \begin{block}{Style Rule \#1}
       
   390     Naming is 80\% of programming
       
   391   \end{block}
       
   392 \end{frame}
       
   393 
       
   394 \section{Simple IO}
   379 \section{Simple IO}
   395 \begin{frame}{Simple IO}
   380 \begin{frame}{Simple IO}
   396   \begin{block}
   381   \begin{block}
   397     {Console Input}
   382     {Console Input}
   398     \texttt{raw\_input()} waits for user input.\\Prompt string is optional.\\
   383     \texttt{raw\_input()} waits for user input.\\Prompt string is optional.\\
   417 \end{frame}
   402 \end{frame}
   418 
   403 
   419 \subsection{Basic Conditional flow}
   404 \subsection{Basic Conditional flow}
   420 \begin{frame}[fragile]
   405 \begin{frame}[fragile]
   421   \frametitle{\typ{If...elif...else} example}
   406   \frametitle{\typ{If...elif...else} example}
   422 \begin{lstlisting}
   407   \begin{lstlisting}
   423 x = int(raw_input("Enter an integer:"))
   408 x = int(raw_input("Enter an integer:"))
   424 if x < 0:
   409 if x < 0:
   425      print 'Be positive!'
   410      print 'Be positive!'
   426 elif x == 0:
   411 elif x == 0:
   427      print 'Zero'
   412      print 'Zero'
   428 elif x == 1:
   413 elif x == 1:
   429      print 'Single'
   414      print 'Single'
   430 else:
   415 else:
   431      print 'More'
   416      print 'More'
   432 \end{lstlisting}
   417   \end{lstlisting}
       
   418   \inctime{10}
   433 \end{frame}
   419 \end{frame}
   434 
   420 
   435 \subsection{Basic Looping}
   421 \subsection{Basic Looping}
   436 \begin{frame}[fragile]
   422 \begin{frame}[fragile]
   437   \frametitle{\typ{while}}
   423   \frametitle{\typ{while}}
   468 1 1
   454 1 1
   469 2 4
   455 2 4
   470 3 9
   456 3 9
   471 4 16
   457 4 16
   472 \end{lstlisting}
   458 \end{lstlisting}
   473 \inctime{15}
   459 \inctime{5}
   474 \end{frame}
   460 \end{frame}
   475 
   461 
   476 \subsection{Exercises}
   462 \subsection{Exercises}
   477 \begin{frame}
   463 \begin{frame}
   478   \frametitle{Problem set 1}
   464   \frametitle{Problem set 1}
   494   \item If the number is even, divide by 2; if the number is odd, multiply by 3 and add 1.
   480   \item If the number is even, divide by 2; if the number is odd, multiply by 3 and add 1.
   495   \item Repeat the procedure with the new number.
   481   \item Repeat the procedure with the new number.
   496   \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops.
   482   \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops.
   497 \end{enumerate}
   483 \end{enumerate}
   498     Write a program that accepts the starting value and prints out the Collatz sequence.
   484     Write a program that accepts the starting value and prints out the Collatz sequence.
   499 
   485 \end{frame}
   500 \end{frame}
   486 
   501 
   487 \begin{frame}[fragile]{Problem 1.3}
   502 \begin{frame}[fragile]{Problem 1.4}
       
   503   Write a program that prints the following pyramid on the screen. 
   488   Write a program that prints the following pyramid on the screen. 
   504   \begin{lstlisting}
   489   \begin{lstlisting}
   505 1
   490 1
   506 2  2
   491 2  2
   507 3  3  3
   492 3  3  3
   508 4  4  4  4
   493 4  4  4  4
   509   \end{lstlisting}
   494   \end{lstlisting}
   510 The number of lines must be obtained from the user as input.\\
   495 The number of lines must be obtained from the user as input.\\
   511 \pause
   496 \pause
   512 \emphbar{When can your code fail?}
   497 \emphbar{When can your code fail?}
   513 \only<2->{\inctime{20}}
   498 \only<2->{\inctime{10}}
       
   499 \end{frame}
       
   500 
       
   501 \begin{frame}[fragile]
       
   502   \frametitle{What did we learn?}
       
   503   \begin{itemize}
       
   504     \item Basic data types
       
   505     \item Arithematic, logical and relational operations
       
   506     \item Conditional structures
       
   507     \item Loops
       
   508   \end{itemize}
   514 \end{frame}
   509 \end{frame}
   515 
   510 
   516 \end{document}
   511 \end{document}