# HG changeset patch # User Santosh G. Vattam # Date 1267507549 -19800 # Node ID 0ba81871dae5583263743a4cb36beb3331323220 # Parent f04eca8b2f3d4142a284929c63a342f0ed045a80# Parent b54a496d320c811cca3b1b841a026139defb0e6c Branches merged. diff -r b54a496d320c -r 0ba81871dae5 day1/day1quiz1.tex --- a/day1/day1quiz1.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day1/day1quiz1.tex Tue Mar 02 10:55:49 2010 +0530 @@ -58,24 +58,25 @@ \end{itemize} \end{frame} +%% \begin{frame}[fragile] +%% \frametitle{\incqno } +%% Draw (roughly) the plot obtained by the following: +%% \begin{lstlisting} +%% In []: x = linspace(0, 2*pi, 3) +%% In []: plot(x, sin(x)) +%% \end{lstlisting} +%% \end{frame} + \begin{frame}[fragile] \frametitle{\incqno } -Draw (roughly) the plot obtained by the following: +Describe the plot produced by the following: \begin{lstlisting} -In []: x = linspace(0, 2*pi, 3) -In []: plot(x, sin(x)) +In []: x = linspace(0, 2*pi, 50) +In []: plot(x, cos(x), 'go') \end{lstlisting} +Note: Do not draw it, just describe the plot \end{frame} -%% \begin{frame}[fragile] -%% \frametitle{\incqno } -%% Describe the plot produced by the following: -%% \begin{lstlisting} -%% In []: x = linspace(0, 2*pi, 50) -%% In []: plot(x, cos(x), 'go') -%% \end{lstlisting} -%% \end{frame} - \begin{frame} \frametitle{\incqno } How will you plot the previous graph with line width set to 3? How will @@ -94,18 +95,18 @@ What ipython magic command do you use to obtain the lines of code you have already typed in the interpreter? What command do you use to save them? \end{frame} -\begin{frame}[fragile] -\frametitle{\incqno } -The following code snippet has an error/bug: -\begin{lstlisting} -In []: y = linspace(0, 2*pi, 50) -In []: plot(y, sin(y)) -In []: clf() -In []: plot(y, cos(y)) -In []: legend(['sin(y)', 'cos(y)']) -\end{lstlisting} -What is the error? How do you fix it? -\end{frame} +%% \begin{frame}[fragile] +%% \frametitle{\incqno } +%% The following code snippet has an error/bug: +%% \begin{lstlisting} +%% In []: y = linspace(0, 2*pi, 50) +%% In []: plot(y, sin(y)) +%% In []: clf() +%% In []: plot(y, cos(y)) +%% In []: legend(['sin(y)', 'cos(y)']) +%% \end{lstlisting} +%% What is the error? How do you fix it? +%% \end{frame} \begin{frame}[fragile] \frametitle{\incqno } @@ -134,15 +135,15 @@ Write the code to read a file \texttt{data.txt} and print each line of it? \end{frame} -\begin{frame}[fragile] -\frametitle{\incqno } -What would be the result of the following code snippet: -\begin{lstlisting} -In []: x = linspace(0, 10, 50) -In []: y = linspace(50, 100, 100) -In []: plot(x, y) -\end{lstlisting} -\end{frame} +%% \begin{frame}[fragile] +%% \frametitle{\incqno } +%% What would be the result of the following code snippet: +%% \begin{lstlisting} +%% In []: x = linspace(0, 10, 50) +%% In []: y = linspace(50, 100, 100) +%% In []: plot(x, y) +%% \end{lstlisting} +%% \end{frame} \begin{frame}[fragile] \frametitle{\incqno } @@ -211,7 +212,7 @@ \frametitle{\incqno } \begin{lstlisting} In []: marks = [10, 20, 30, 50, 55, - 75, 83] + 75, 83] \end{lstlisting} How will you convert the list \texttt{marks} to an \alert{array}? \end{frame} diff -r b54a496d320c -r 0ba81871dae5 day1/day1quiz2.tex --- a/day1/day1quiz2.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day1/day1quiz2.tex Tue Mar 02 10:55:49 2010 +0530 @@ -35,7 +35,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Title page -\title[Basic Python]{Python for science and engineering: Day 1, Quiz 2} +\title[Basic Python]{Python for science and engineering: Day 2, Quiz 1} \author[FOSSEE Team] {FOSSEE} diff -r b54a496d320c -r 0ba81871dae5 day1/session1.tex --- a/day1/session1.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day1/session1.tex Tue Mar 02 10:55:49 2010 +0530 @@ -77,7 +77,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 1} +\date[] {12 February, 2010\\Day 1, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -125,55 +125,41 @@ \begin{frame} \frametitle{Workshop Schedule: Day 1} \begin{description} - \item[Session 1] Mon 09:00--10:00 - \item[Session 2] Mon 10:05--11:05 - \item[Session 3] Mon 11:20--12:20 - \item[Session 4] Mon 12:25--13:25 - \item[Quiz 1] Mon 14:25--14:40 - \item[Exercises] Mon 14:40--15:25 - \item[Session 5] Mon 15:40--16:40 - \item[Quiz 2] Mon 16:45--17:00 + \item[Session 1] Fri 14:00--15:00 + \item[Session 2] Fri 15:05--16:05 + \item[Session 3] Fri 16:10--17:10 + \item[Quiz 1] Fri 17:10--17:25 + \item[Exercises] Thu 17:30--18:00 \end{description} \end{frame} \begin{frame} \frametitle{Workshop Schedule: Day 2} \begin{description} - \item[Session 1] Tue 09:00--10:00 - \item[Session 2] Tue 10:05--11:05 - \item[Session 3] Tue 11:20--12:20 - \item[Session 4] Tue 12:25--13:25 - \item[Quiz 1] Tue 14:25--14:40 - \item[Exercises] Tue 14:40--15:25 - \item[Session 5] Tue 15:40--16:40 - \item[Quiz 2] Tue 16:45--17:00 + \item[Session 1] Sat 09:00--10:00 + \item[Session 2] Sat 10:05--11:05 + \item[Session 3] Sat 11:20--12:20 + \item[Quiz 2] Fri 14:25--14:40 \end{description} \end{frame} \begin{frame} - \frametitle{About the Workshop} - \begin{block}{Intended Audience} - \begin{itemize} - \item Engg., Mathematics and Science teachers. - \item Interested students from similar streams. - \end{itemize} - \end{block} - - \begin{block}{Goal: Successful participants will be able to} - \begin{itemize} - \item Use Python as plotting, computational tool. - \item Understand how to use Python as a scripting and problem solving language. - \item Train students for the same. - \end{itemize} - \end{block} + \frametitle{Workshop Schedule: Day 3} + \begin{description} + \item[Session 1] Sun 09:00--10:00 + \item[Session 2] Sun 10:05--11:05 + \item[Session 3] Sun 11:20--12:20 + \item[Quiz 3] Sun 12:20--12:30 + \item[Exercises] Sun 12:30--13:00 + \end{description} \end{frame} -\section{Getting started} +\section{Checklist} \begin{frame} \frametitle{Checklist} \begin{enumerate} \item IPython - \item Editor: We recommend \alert{scite}. + \item Editor \item Data files: \begin{itemize} \item \typ{sslc1.txt} @@ -195,6 +181,25 @@ \end{enumerate} \end{frame} +\begin{frame} + \frametitle{About the Workshop} + \begin{block}{Intended Audience} + \begin{itemize} + \item Engg., Mathematics and Science teachers. + \item Interested students from similar streams. + \end{itemize} + \end{block} + + \begin{block}{Goal: Successful participants will be able to} + \begin{itemize} + \item Use Python as plotting, computational tool. + \item Understand how to use Python as a scripting and problem solving language. + \item Train students for the same. + \end{itemize} + \end{block} +\end{frame} + +\section{Starting up Ipython} \begin{frame}[fragile] \frametitle{Starting up \ldots} \begin{block}{} @@ -207,7 +212,7 @@ Hello, World! \end{lstlisting} Exiting -\begin{lstlisting} +\begin{lstlisting} In []: ^D(Ctrl-D) Do you really want to exit([y]/n)? y \end{lstlisting} @@ -235,23 +240,22 @@ \alert{IPython provides many additional features}\\ \end{frame} -%% \begin{frame}[fragile] -%% \frametitle{Loops} -%% Breaking out of loops -%% \begin{lstlisting} -%% In []: while True: -%% ...: print "Hello, World!" -%% ...: -%% Hello, World! -%% Hello, World!^C(Ctrl-C) -%% ------------------------------------ -%% KeyboardInterrupt - -%% \end{lstlisting} -%% \end{frame} +\section{Loops} +\begin{frame}[fragile] +\frametitle{Loops} +Breaking out of loops +\begin{lstlisting} + In []: while True: + ...: print "Hello, World!" + ...: + Hello, World! + Hello, World!^C(Ctrl-C) + ------------------------------------ + KeyboardInterrupt +\end{lstlisting} +\end{frame} \section{Plotting} - \subsection{Drawing plots} \begin{frame}[fragile] \frametitle{First Plot} @@ -271,7 +275,6 @@ \end{columns} \end{frame} - \begin{frame}[fragile] \frametitle{Walkthrough} \begin{block}{\typ{x = linspace(start, stop, num)} } @@ -413,8 +416,10 @@ In []: plot(y, sin(y)) In []: figure(2) In []: plot(y, cos(y)) +In []: savefig('cosine.png') In []: figure(1) In []: title('sin(y)') +In []: savefig('sine.png') In []: close() In []: close() \end{lstlisting} @@ -424,10 +429,10 @@ \frametitle{Showing it better} \vspace{-0.15in} \begin{lstlisting} -In []: plot(y, sin(y), 'g') +In []: plot(y, cos(y), 'r') In []: clf() -In []: plot(y, cos(y), 'r', linewidth=2) +In []: plot(y, sin(y), 'g', linewidth=2) \end{lstlisting} \vspace*{-0.2in} \begin{center} @@ -457,8 +462,7 @@ \end{lstlisting} \emphbar{Set the axes limits} \begin{lstlisting} -In []: xmax = 2*pi -In []: xlim(xmin, xmax) +In []: xlim(xmin, 2*pi) In []: ylim(ymin-0.2, ymax+0.2) \end{lstlisting} \end{frame} @@ -512,7 +516,7 @@ \begin{itemize} \item Use \typ{\%hist} command of IPython \item Identify the required line numbers -\item Then, use \typ{\%save} command of IPython +\item Then, use \typ{\%save} command of IPython \end{itemize} \typ{In []: \%hist}\\ \typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} @@ -533,8 +537,9 @@ \begin{frame}[fragile] \frametitle{What did we learn?} \begin{itemize} - \item \kwrd{\%hist} - \item Saving commands to a script + \item Starting up IPython + \item \kwrd{\%hist} - History of commands + \item \kwrd{\%save} - Saving commands \item Running a script using \kwrd{\%run -i} \item Creating simple plots. \item Adding labels and legends. diff -r b54a496d320c -r 0ba81871dae5 day1/session2.tex --- a/day1/session2.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day1/session2.tex Tue Mar 02 10:55:49 2010 +0530 @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 2} +\date[] {12 February, 2010\\Day 1, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -179,10 +179,10 @@ \begin{frame}[fragile] \frametitle{Additional Plotting Attributes} \begin{itemize} - \item \typ{'o'} - Filled circles - \item \typ{'.'} - Small Dots - \item \typ{'-'} - Lines - \item \typ{'--'} - Dashed lines + \item \kwrd{'o'} - Filled circles + \item \kwrd{'.'} - Small Dots + \item \kwrd{'-'} - Lines + \item \kwrd{'- -'} - Dashed lines \end{itemize} \end{frame} @@ -190,7 +190,7 @@ \begin{frame}[fragile] \frametitle{Lists: Introduction} \begin{lstlisting} - In []: x = [4, 2, 1, 3] + In []: x = [0, 1, 2, 3] In []: y = [7, 11, 15, 19] @@ -208,43 +208,45 @@ \end{lstlisting} \emphbar{Empty List} \begin{lstlisting} -In []: a = [ 5, 2, 3, 1, 4] +In []: p = [ 2, 3, 5, 7] -In []: a[0]+a[1]+a[-1] -Out[]: 11 +In []: p[0]+p[1]+p[-1] +Out[]: 12 \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{List: Slicing} \begin{block}{Remember\ldots} - \kwrd{In []: a = [ 5, 2, 3, 1, 4]} + \kwrd{In []: p = [ 2, 3, 5, 7]} \end{block} \begin{lstlisting} -In []: a[1:3] -Out[]: [2, 3] +In []: p[1:3] +Out[]: [3, 5] \end{lstlisting} \emphbar{A slice} \begin{lstlisting} -In []: a[1:-1] -Out[]: [2, 3, 1] +In []: p[0:-1] +Out[]: [2, 3, 5] +In []: p[::2] +Out[]: [2, 5] \end{lstlisting} -\alert{\typ{list[initial:final]}} +\alert{\typ{list[initial:final:step]}} \end{frame} %% more on list slicing \begin{frame}[fragile] \frametitle{List operations} \begin{lstlisting} -In []: b = [ 8, 6, 9, 9] -In []: c = a + b +In []: b = [ 11, 13, 17] +In []: c = p + b In []: c -Out[]: [5, 2, 3, 1, 4, 8, 6, 9, 9] +Out[]: [2, 3, 5, 7, 11, 13, 17] -In []: a.append(6) -In []: a -Out[]: [5, 2, 3, 1, 4, 6] +In []: p.append(11) +In []: p +Out[]: [ 2, 3, 5, 7, 11] \end{lstlisting} %\inctime{10} \end{frame} @@ -299,27 +301,40 @@ \begin{lstlisting} In []: tsq = [] +In []: len(l) +Out[]: 9 + +In []: len(t) +Out[]: 9 + In []: for time in t: ....: tsq.append(time*time) ....: ....: + +In []: plot(l, tsq) +Out[]: [] \end{lstlisting} -Hit the ``ENTER'' key twice to come to the previous indentation level -\begin{lstlisting} -In []: print tsq -\end{lstlisting} -\kwrd{tsq} is the list of squares of \typ{t} values. +This gives \kwrd{tsq} which is the list of squares of \typ{t} values. \end{frame} \begin{frame}[fragile] -\frametitle{Plotting $L$ vs $T^2$ \ldots} -\begin{lstlisting} -In []: plot(l, tsq) -Out[]: [] -\end{lstlisting} -This gives the required plot. + \frametitle{How to come out of the \texttt{for} loop?} + Hitting the ``ENTER'' key twice returns the cursor to the previous indentation level + \begin{lstlisting} + In []: for time in t: + ....: tsq.append(time*time) + ....: + ....: + + In []: print tsq, len(tsq) + In []: plot(l, tsq) + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] \begin{figure} -\includegraphics[width=2.2in]{data/L-TSq-limited.png} +\includegraphics[width=3.5in]{data/L-TSq-limited.png} \end{figure} \end{frame} @@ -353,7 +368,7 @@ \begin{frame}[fragile] \frametitle{Plotting from \typ{pendulum.txt}} -Type the following in an editor. Save as \typ{pend\_pl.py} +Open a new script and type the following: \begin{lstlisting} l = [] t = [] @@ -365,15 +380,14 @@ for time in t: tsq.append(time*time) plot(l, tsq, '.') -show() \end{lstlisting} \end{frame} \begin{frame} \frametitle{Save and run} \begin{itemize} - \item Save as \typ{pend\_pl.py} - \item Run using \kwrd{\%run -i pend\_pl.py} + \item Save as pendulum\_plot.py. + \item Run using \kwrd{\%run -i pendulum\_plot.py} \end{itemize} \end{frame} @@ -452,7 +466,6 @@ for time in t: tsq.append(time*time) plot(l, tsq, '.') -show() \end{lstlisting} \end{frame} diff -r b54a496d320c -r 0ba81871dae5 day1/session3.tex --- a/day1/session3.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day1/session3.tex Tue Mar 02 10:55:49 2010 +0530 @@ -79,7 +79,7 @@ \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 3} +\date[] {12 February, 2010\\Day 1, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -319,7 +319,7 @@ \end{lstlisting} \begin{itemize} \item Keys will be region codes - \item Values will be the number students who scored more than 90\% in that region + \item Values will be the number students who scored more than 90\% in that region in Science \end{itemize} \begin{block}{Sample \emph{science} dictionary} \{'A': 729, 'C': 764, 'B': 1120,'E': 414, 'D': 603, 'F': 500\} diff -r b54a496d320c -r 0ba81871dae5 day1/session4.tex --- a/day1/session4.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day1/session4.tex Tue Mar 02 10:55:49 2010 +0530 @@ -79,7 +79,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 4} +\date[] {13 February, 2010\\Day 2, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -279,6 +279,21 @@ \end{frame} \begin{frame}[fragile] + \frametitle{Shape of a matrix} + \begin{lstlisting} +In []: c +Out[]: +array([[11, 12, 13], + [ 0, 0, 0], + [31, 32, 33]]) + +In []: c.shape +Out[]: (3, 3) + \end{lstlisting} +\emphbar{Shape specifies shape or dimensions of a matrix} +\end{frame} + +\begin{frame}[fragile] \frametitle{Slicing \& Striding Exercises} \begin{small} \begin{lstlisting} @@ -518,7 +533,7 @@ \begin{frame}[fragile] \frametitle{Getting $L$ and $T^2$} -If you \alert{closed} IPython after session 2 +%If you \alert{closed} IPython after session 2 \begin{lstlisting} In []: l = [] In []: t = [] diff -r b54a496d320c -r 0ba81871dae5 day1/session5.tex --- a/day1/session5.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day1/session5.tex Tue Mar 02 10:55:49 2010 +0530 @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 5} +\date[] {12 February, 2010\\Day 1, Session 5} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -127,10 +127,7 @@ point = line.split() l.append(float(point[0])) t.append(float(point[1])) -tsq = [] -for time in t: - tsq.append(time*time) -plot(l, tsq, '.') +plot(l, t, '.') \end{lstlisting} \end{block} \end{columns} @@ -192,7 +189,7 @@ \begin{frame}[fragile] \frametitle{Problem 3 cont...} -Create a sequence of images in which the damped oscillator($e^{x/10}sin(x)$) slowly evolves over time. +Create a sequence of images in which the damped oscillator($e^{-x/10}sin(x)$) slowly evolves over time. \begin{columns} \column{0.35\textwidth} \includegraphics[width=1.5in,height=1.5in, interpolate=true]{data/plot2} diff -r b54a496d320c -r 0ba81871dae5 day1/session6.tex --- a/day1/session6.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day1/session6.tex Tue Mar 02 10:55:49 2010 +0530 @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 6} +\date[] {13 February, 2010\\Day 2, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} diff -r b54a496d320c -r 0ba81871dae5 day2/day2quiz.tex --- a/day2/day2quiz.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day2/day2quiz.tex Tue Mar 02 10:55:49 2010 +0530 @@ -40,7 +40,7 @@ \author[FOSSEE Team] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {\today \\ Day 2, Quiz 1} +\date[] {\today \\ Day 2, Quiz} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -94,7 +94,7 @@ \begin{frame} \frametitle{\incqno } - What does '*' * 40 produce? + What does 't' * 40 produce? \end{frame} \begin{frame}[fragile] diff -r b54a496d320c -r 0ba81871dae5 day2/session1.tex --- a/day2/session1.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day2/session1.tex Tue Mar 02 10:55:49 2010 +0530 @@ -79,7 +79,7 @@ \author[FOSSEE Team] {The FOSSEE Group} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {12 January, 2010\\Day 2, Session 1} +\date[] {13 February, 2010\\Day 2, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -255,6 +255,7 @@ \begin{frame}[fragile] \frametitle{A bit about IPython} + Recall, we showed a few features of IPython, here is one more: \begin{itemize} \item IPython provides better help \item object.function? @@ -262,10 +263,6 @@ In []: a = 'Hello World' In []: a.lower? \end{lstlisting} - \item It provides tab completion - \begin{lstlisting} -In []: a.s - \end{lstlisting} \end{itemize} \end{frame} @@ -278,6 +275,9 @@ \begin{lstlisting} In []: ''.join(['a', 'b', 'c']) Out[]: 'abc' + +In []: ', '.join(['a', 'b', 'c']) +Out[]: 'a, b, c' \end{lstlisting} \end{frame} @@ -511,7 +511,7 @@ \subsection{Basic Conditional flow} \begin{frame}[fragile] \frametitle{\typ{If...elif...else} example} -Type out the code below in an editor. +Type the following code in an editor \& save as \alert{ladder.py} \small \begin{lstlisting} x = int(raw_input("Enter an integer:")) diff -r b54a496d320c -r 0ba81871dae5 day2/session2.tex --- a/day2/session2.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day2/session2.tex Tue Mar 02 10:55:49 2010 +0530 @@ -78,7 +78,7 @@ \author[FOSSEE Team] {The FOSSEE Group} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {12 January, 2010\\Day 2, Session 2} +\date[] {13 February, 2010\\Day 3, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -208,19 +208,6 @@ \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops. \end{enumerate} Write a program that accepts the starting value and prints out the Collatz sequence. -\end{frame} - -\begin{frame}[fragile]{Problem 1.3} - Write a program that prints the following pyramid on the screen. - \begin{lstlisting} -1 -2 2 -3 3 3 -4 4 4 4 - \end{lstlisting} -The number of lines must be obtained from the user.\\ -\pause -\emphbar{When can your code fail?} \inctime{5} \end{frame} @@ -519,6 +506,24 @@ \end{lstlisting} \end{frame} +\begin{frame}[fragile] + \frametitle {What does this function do?} + \begin{lstlisting} +def what( x, n ): + if n < 0: + n = -n + x = 1.0 / x + + z = 1.0 + while n > 0: + if n % 2 == 1: + z *= x + x *= x + n /= 2 + return z + \end{lstlisting} +\end{frame} + \begin{frame} \frametitle{What did we learn?} \begin{itemize} diff -r b54a496d320c -r 0ba81871dae5 day2/session3.tex --- a/day2/session3.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day2/session3.tex Tue Mar 02 10:55:49 2010 +0530 @@ -78,7 +78,7 @@ \author[FOSSEE Team] {The FOSSEE Group} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {12 January, 2010\\Day 2, Session 3} +\date[] {13 February, 2010\\Day 3, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} diff -r b54a496d320c -r 0ba81871dae5 day2/session4.tex --- a/day2/session4.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day2/session4.tex Tue Mar 02 10:55:49 2010 +0530 @@ -100,7 +100,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {12 January, 2010\\Day 2, Session 4} +\date[] {13 February, 2010\\Day 3, Session 4} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo} diff -r b54a496d320c -r 0ba81871dae5 day2/session5.tex --- a/day2/session5.tex Thu Feb 04 23:15:50 2010 +0530 +++ b/day2/session5.tex Tue Mar 02 10:55:49 2010 +0530 @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {12 January, 2010\\Day 2, Session 5} +\date[] {13 February, 2010\\Day 3, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}