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} |
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}} |
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} |