diff options
author | Anoop Jacob Thomas | 2010-10-27 19:22:08 +0530 |
---|---|---|
committer | Anoop Jacob Thomas | 2010-10-27 19:22:08 +0530 |
commit | 32be791b6a05a6bbd1aaab5d07b74a7fc53a015a (patch) | |
tree | a5f4e37508e875cccf85c798607fdd4238334e15 /loops | |
parent | ff6510a1cc76c767a65f3b5bda672e3503426b05 (diff) | |
download | st-scripts-32be791b6a05a6bbd1aaab5d07b74a7fc53a015a.tar.gz st-scripts-32be791b6a05a6bbd1aaab5d07b74a7fc53a015a.tar.bz2 st-scripts-32be791b6a05a6bbd1aaab5d07b74a7fc53a015a.zip |
reviewed the script loops.
Diffstat (limited to 'loops')
-rw-r--r-- | loops/script.rst | 31 | ||||
-rw-r--r-- | loops/slides.tex | 18 |
2 files changed, 36 insertions, 13 deletions
diff --git a/loops/script.rst b/loops/script.rst index ead076d..2957e25 100644 --- a/loops/script.rst +++ b/loops/script.rst @@ -16,8 +16,8 @@ .. #. conditionals -.. Author : - Internal Reviewer : +.. Author : Puneeth + Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in> External Reviewer : Checklist OK? : <put date stamp here, if OK> [2010-10-05] @@ -26,7 +26,7 @@ Script {{{ Show the slide containing title }}} -Hello Friends. Welcome this tutorial on loops in Python. +Hello Friends. Welcome to the tutorial on loops in Python. {{{ Show the outline slide }}} @@ -34,6 +34,13 @@ In this tutorial, we shall look at ``while`` and ``for`` loops. We shall then look at the ``break``, ``continue`` and ``pass`` keywords and how to use them. +.. #[[Anoop: for loop is a pre-requisite and has been already covered, + so i think our emphasize can be on while loops]] + +.. #[[Anoop: Instead of saying we will learn keywords pass, break and + continue, I think it is better to tell them that we will learn more + about loops]] + {{{ switch to the ipython terminal }}} We have an ``ipython`` terminal, that we shall use through out this @@ -60,6 +67,8 @@ executes the block of code within the loop, if it is. As with any other block in Python, the code within the ``while`` block is indented to the right by 4 spaces. +{{{ switch to next slide }}} + Following is an exercise that you must do. %%1%% Write a ``while`` loop to print the squares of all the even @@ -67,6 +76,8 @@ numbers below 10. Please, pause the video here. Do the exercise and then continue. +{{{ switch to next slide after a seconds break}}} + :: i = 2 @@ -88,11 +99,15 @@ then iterate over it and print the required stuff. Following is an exercise that you must do. +{{{ switch to next slide }}} + %%2%% Write a ``for`` loop to print the squares of all the even numbers below 10. Please, pause the video here. Do the exercise and then continue. +{{{ switch to next slide after a seconds break }}} + :: for n in range(2, 10, 2): @@ -126,6 +141,8 @@ modified using the ``break`` statement, as follows ``continue`` is used to skip execution of the rest of the loop on this iteration and continue to the end of this iteration. +.. #[[Anoop: should add slides for break, continue, pass]] + Say, we wish to print the squares of all the odd numbers below 10, which are not multiples of 3, we would modify the for loop as follows. :: @@ -138,11 +155,19 @@ which are not multiples of 3, we would modify the for loop as follows. Following is an exercise that you must do. +{{{ switch to next slide }}} + %%3%%Using the ``continue`` keyword modify the ``for`` loop to print the squares of even numbers below 10, to print the squares of only multiples of 4. (Do not modify the range function call.) +.. #[[Anoop: can you be more explicit/specific on do no modify say we + can ask them to use range(2, 10, 2) and solve the problem]] + Please, pause the video here. Do the exercise and then continue. + +{{{ switch to next slide after a seconds break}}} + :: for n in range(2, 10, 2): diff --git a/loops/slides.tex b/loops/slides.tex index 245bb7e..1713886 100644 --- a/loops/slides.tex +++ b/loops/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-10-10 Sun 21:15 +% Created 2010-10-27 Wed 17:51 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -8,6 +8,7 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} +\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} @@ -62,14 +63,13 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \frametitle{Solution 1} \label{sec-3} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: i = 2 In []: while i<10: ....: print i*i ....: i += 2 -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 2} @@ -82,11 +82,10 @@ In []: while i<10: \frametitle{Solution 2} \label{sec-5} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: for n in range(2, 10, 2): ....: print n*n -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 3} @@ -100,13 +99,12 @@ In []: for n in range(2, 10, 2): \frametitle{Solution 3} \label{sec-7} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} for n in range(2, 10, 2): if n%4: continue print n*n -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Summary} |