loops/slides.tex
author Anoop Jacob Thomas<anoop@fossee.in>
Wed, 27 Oct 2010 19:22:08 +0530
changeset 365 0fbe8a18587f
parent 278 461a68dbefb1
permissions -rw-r--r--
reviewed the script loops.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
365
0fbe8a18587f reviewed the script loops.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 278
diff changeset
     1
% Created 2010-10-27 Wed 17:51
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     2
\documentclass[presentation]{beamer}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
\usepackage[latin1]{inputenc}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
\usepackage[T1]{fontenc}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     5
\usepackage{fixltx2e}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     6
\usepackage{graphicx}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     7
\usepackage{longtable}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     8
\usepackage{float}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     9
\usepackage{wrapfig}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    10
\usepackage{soul}
365
0fbe8a18587f reviewed the script loops.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 278
diff changeset
    11
\usepackage{t1enc}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    12
\usepackage{textcomp}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    13
\usepackage{marvosym}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    14
\usepackage{wasysym}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    15
\usepackage{latexsym}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    16
\usepackage{amssymb}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    17
\usepackage{hyperref}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    18
\tolerance=1000
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    19
\usepackage[english]{babel} \usepackage{ae,aecompl}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    20
\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    21
\usepackage{listings}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    22
\lstset{language=Python, basicstyle=\ttfamily\bfseries,
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    23
commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    24
showstringspaces=false, keywordstyle=\color{blue}\bfseries}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    25
\providecommand{\alert}[1]{\textbf{#1}}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    27
\title{Loops}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    28
\author{FOSSEE}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
\date{}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    31
\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
\begin{document}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    33
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    34
\maketitle
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    35
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    36
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    37
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    38
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    39
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    40
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    41
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    42
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    43
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    44
\begin{frame}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    45
\frametitle{Outline}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    46
\label{sec-1}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    47
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    48
\begin{itemize}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    49
\item Loop while a condition is true.
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    50
\item Iterate over a sequence
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    51
\item Breaking out of loops.
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    52
\item Skipping iterations.
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    53
\end{itemize}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    54
\end{frame}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    55
\begin{frame}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    56
\frametitle{Question 1}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    57
\label{sec-2}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    58
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    59
  Write a \texttt{while} loop to print the squares of all the even
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    60
  numbers below 10. 
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    61
\end{frame}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    62
\begin{frame}[fragile]
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    63
\frametitle{Solution 1}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    64
\label{sec-3}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    65
365
0fbe8a18587f reviewed the script loops.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 278
diff changeset
    66
\begin{verbatim}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    67
In []: i = 2
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    68
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    69
In []:  while i<10:
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    70
 ....:     print i*i
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    71
 ....:     i += 2
365
0fbe8a18587f reviewed the script loops.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 278
diff changeset
    72
\end{verbatim}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    73
\end{frame}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    74
\begin{frame}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    75
\frametitle{Question 2}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    76
\label{sec-4}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    77
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    78
  Write a \texttt{for} loop to print the squares of all the even numbers
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    79
  below 10.
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    80
\end{frame}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    81
\begin{frame}[fragile]
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    82
\frametitle{Solution 2}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    83
\label{sec-5}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    84
365
0fbe8a18587f reviewed the script loops.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 278
diff changeset
    85
\begin{verbatim}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    86
In []: for n in range(2, 10, 2):
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    87
 ....:     print n*n
365
0fbe8a18587f reviewed the script loops.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 278
diff changeset
    88
\end{verbatim}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    89
\end{frame}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    90
\begin{frame}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    91
\frametitle{Question 3}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    92
\label{sec-6}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    93
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    94
  Using the \texttt{continue} keyword modify the \texttt{for} loop to print the
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    95
  squares of even numbers below 10, to print the squares of only
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    96
  multiples of 4. (Do not modify the range function call.)
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    97
\end{frame}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    98
\begin{frame}[fragile]
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    99
\frametitle{Solution 3}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   100
\label{sec-7}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   101
365
0fbe8a18587f reviewed the script loops.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 278
diff changeset
   102
\begin{verbatim}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   103
for n in range(2, 10, 2):
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   104
    if n%4:
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   105
        continue      
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   106
    print n*n
365
0fbe8a18587f reviewed the script loops.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 278
diff changeset
   107
\end{verbatim}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   108
\end{frame}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   109
\begin{frame}
278
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   110
\frametitle{Summary}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   111
\label{sec-8}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   112
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   113
  You should now be able to --
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   114
\begin{itemize}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   115
\item use the \texttt{for} loop
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   116
\item use the \texttt{while} loop
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   117
\item Use \texttt{break}, \texttt{continue} and \texttt{pass} statements
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   118
\end{itemize}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   119
\end{frame}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   120
\begin{frame}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   121
\frametitle{Thank you!}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   122
\label{sec-9}
461a68dbefb1 Slides for loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   123
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   124
  \begin{block}{}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   125
  \begin{center}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   126
  This spoken tutorial has been produced by the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   127
  \textcolor{blue}{FOSSEE} team, which is funded by the 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   128
  \end{center}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   129
  \begin{center}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   130
    \textcolor{blue}{National Mission on Education through \\
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   131
      Information \& Communication Technology \\ 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   132
      MHRD, Govt. of India}.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   133
  \end{center}  
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   134
  \end{block}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   135
\end{frame}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   136
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   137
\end{document}