conditionals/slides.org
changeset 438 4523b2048663
parent 437 0840aa06d2e6
equal deleted inserted replaced
437:0840aa06d2e6 438:4523b2048663
    28 #+LANGUAGE:  en
    28 #+LANGUAGE:  en
    29 #+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
    29 #+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
    30 #+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
    30 #+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
    31 
    31 
    32 * Outline
    32 * Outline
       
    33   In this tutorial, we shall look at
       
    34     + Using if/else blocks 
       
    35     + Using if/elif/else blocks
       
    36     + Using the Ternary conditional statement
    33 
    37 
    34 * Question 1
    38 * Question 1
    35 
    39   Given a number, num. Write an if else block to print num, as is, if
       
    40   it is divisible by 10, else print 10 * num.
    36 * Solution 1
    41 * Solution 1
    37   #+begin_src python
    42   #+begin_src python
    38 
    43     if num%10 == 0: 
       
    44         print num   
       
    45     else:           
       
    46         print 10*num
    39   #+end_src
    47   #+end_src
    40 
    48 
    41 * ~if/elif~ ladder
    49 * ~if/elif~ ladder
    42   #+begin_src python
    50   #+begin_src python
    43     if user == 'admin':
    51     if user == 'admin':
    45     elif user == 'moderator':
    53     elif user == 'moderator':
    46         # Do moderator operations
    54         # Do moderator operations
    47     elif user == 'client':
    55     elif user == 'client':
    48         # Do customer operations
    56         # Do customer operations
    49   #+end_src
    57   #+end_src
       
    58 * Question 2
       
    59   Given a number, num. Write a ternary operator to print num, as is,
       
    60   if it is divisible by 10, else print 10 * num.
       
    61 * Solution 2
       
    62   #+begin_src python
       
    63     print num if num%10 == 0 else 10*num
       
    64   #+end_src
       
    65 * Summary
       
    66   In this tutorial session we learnt
    50 
    67 
    51 * Summary
    68     + What are conditional statements
       
    69     + if/else statement
       
    70     + if/elif/else statement
       
    71     + Ternary conditional statement - ~C if X else Y~
       
    72     + and the ~pass~ statement
    52 
    73 
    53 * Thank you!
    74 * Thank you!
    54 #+begin_latex
    75 #+begin_latex
    55   \begin{block}{}
    76   \begin{block}{}
    56   \begin{center}
    77   \begin{center}