conditionals/slides.tex
author bhanu
Thu, 11 Nov 2010 03:00:24 +0530
changeset 480 42f7aa36f1bc
parent 438 4523b2048663
permissions -rw-r--r--
language check done for `getting started with functions`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
     1
% Created 2010-11-10 Wed 13:25
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
     2
\documentclass[presentation]{beamer}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
\usepackage[latin1]{inputenc}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
\usepackage[T1]{fontenc}
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
     5
\usepackage{fixltx2e}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
     6
\usepackage{graphicx}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
     7
\usepackage{longtable}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
     8
\usepackage{float}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
     9
\usepackage{wrapfig}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    10
\usepackage{soul}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    11
\usepackage{textcomp}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    12
\usepackage{marvosym}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    13
\usepackage{wasysym}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    14
\usepackage{latexsym}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    15
\usepackage{amssymb}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    16
\usepackage{hyperref}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    17
\tolerance=1000
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    18
\usepackage[english]{babel} \usepackage{ae,aecompl}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    19
\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    20
\usepackage{listings}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    21
\lstset{language=Python, basicstyle=\ttfamily\bfseries,
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    22
commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    23
showstringspaces=false, keywordstyle=\color{blue}\bfseries}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    24
\providecommand{\alert}[1]{\textbf{#1}}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    26
\title{Conditionals}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    27
\author{FOSSEE}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
\date{}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    30
\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    31
\begin{document}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    33
\maketitle
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    34
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    35
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    36
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    37
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    38
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    39
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    40
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    41
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    42
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    43
\begin{frame}
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    44
\frametitle{Outline}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    45
\label{sec-1}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    46
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    47
  In this tutorial, we shall look at
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    48
\begin{itemize}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    49
\item Using if/else blocks
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    50
\item Using if/elif/else blocks
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    51
\item Using the Ternary conditional statement
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    52
\end{itemize}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    53
\end{frame}
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    54
\begin{frame}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    55
\frametitle{Question 1}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    56
\label{sec-2}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    57
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    58
  Given a number, num. Write an if else block to print num, as is, if
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    59
  it is divisible by 10, else print 10 * num.
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    60
\end{frame}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    61
\begin{frame}[fragile]
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    62
\frametitle{Solution 1}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    63
\label{sec-3}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    64
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    65
\lstset{language=Python}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    66
\begin{lstlisting}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    67
if num%10 == 0: 
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    68
    print num   
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    69
else:           
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    70
    print 10*num
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    71
\end{lstlisting}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    72
\end{frame}
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    73
\begin{frame}[fragile]
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    74
\frametitle{\texttt{if/elif} ladder}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    75
\label{sec-4}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    76
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    77
\lstset{language=Python}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    78
\begin{lstlisting}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    79
if user == 'admin':
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    80
    # Do admin operations
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    81
elif user == 'moderator':
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    82
    # Do moderator operations
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    83
elif user == 'client':
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    84
    # Do customer operations
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    85
\end{lstlisting}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    86
\end{frame}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    87
\begin{frame}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    88
\frametitle{Question 2}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    89
\label{sec-5}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    90
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    91
  Given a number, num. Write a ternary operator to print num, as is,
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    92
  if it is divisible by 10, else print 10 * num.
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    93
\end{frame}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    94
\begin{frame}[fragile]
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    95
\frametitle{Solution 2}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    96
\label{sec-6}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    97
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    98
\lstset{language=Python}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
    99
\begin{lstlisting}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   100
print num if num%10 == 0 else 10*num
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   101
\end{lstlisting}
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   102
\end{frame}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   103
\begin{frame}
438
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   104
\frametitle{Summary}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   105
\label{sec-7}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   106
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   107
  In this tutorial session we learnt
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   108
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   109
\begin{itemize}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   110
\item What are conditional statements
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   111
\item if/else statement
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   112
\item if/elif/else statement
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   113
\item Ternary conditional statement - \texttt{C if X else Y}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   114
\item and the \texttt{pass} statement
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   115
\end{itemize}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   116
\end{frame}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   117
\begin{frame}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   118
\frametitle{Thank you!}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   119
\label{sec-8}
4523b2048663 Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 315
diff changeset
   120
315
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   121
  \begin{block}{}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   122
  \begin{center}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   123
  This spoken tutorial has been produced by the
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   124
  \textcolor{blue}{FOSSEE} team, which is funded by the 
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   125
  \end{center}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   126
  \begin{center}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   127
    \textcolor{blue}{National Mission on Education through \\
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   128
      Information \& Communication Technology \\ 
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   129
      MHRD, Govt. of India}.
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   130
  \end{center}  
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   131
  \end{block}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   132
\end{frame}
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   133
7944a4504769 Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   134
\end{document}