author | anand |
Mon, 15 Nov 2010 15:08:22 +0530 | |
changeset 506 | ea74e6056453 |
parent 438 | 4523b2048663 |
permissions | -rw-r--r-- |
315
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
1 |
#+LaTeX_CLASS: beamer |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
2 |
#+LaTeX_CLASS_OPTIONS: [presentation] |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
3 |
#+BEAMER_FRAME_LEVEL: 1 |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
4 |
|
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
5 |
#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
6 |
#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
7 |
#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
8 |
|
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
9 |
#+LaTeX_CLASS: beamer |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
10 |
#+LaTeX_CLASS_OPTIONS: [presentation] |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
11 |
|
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
12 |
#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
13 |
#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
14 |
|
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
15 |
#+LaTeX_HEADER: \usepackage{listings} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
16 |
|
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
17 |
#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
18 |
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
19 |
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
20 |
|
437
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
21 |
#+TITLE: Conditionals |
315
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
22 |
#+AUTHOR: FOSSEE |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
23 |
#+EMAIL: |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
24 |
#+DATE: |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
25 |
|
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
26 |
#+DESCRIPTION: |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
27 |
#+KEYWORDS: |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
28 |
#+LANGUAGE: en |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
29 |
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
30 |
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
31 |
|
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
32 |
* Outline |
438
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
33 |
In this tutorial, we shall look at |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
34 |
+ Using if/else blocks |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
35 |
+ Using if/elif/else blocks |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
36 |
+ Using the Ternary conditional statement |
437
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
37 |
|
315
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
38 |
* Question 1 |
438
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
39 |
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:
437
diff
changeset
|
40 |
it is divisible by 10, else print 10 * num. |
315
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
41 |
* Solution 1 |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
42 |
#+begin_src python |
438
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
43 |
if num%10 == 0: |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
44 |
print num |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
45 |
else: |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
46 |
print 10*num |
315
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
47 |
#+end_src |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
48 |
|
437
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
49 |
* ~if/elif~ ladder |
315
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
50 |
#+begin_src python |
437
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
51 |
if user == 'admin': |
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
52 |
# Do admin operations |
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
53 |
elif user == 'moderator': |
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
54 |
# Do moderator operations |
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
55 |
elif user == 'client': |
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
56 |
# Do customer operations |
315
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
57 |
#+end_src |
438
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
58 |
* Question 2 |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
59 |
Given a number, num. Write a ternary operator to print num, as is, |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
60 |
if it is divisible by 10, else print 10 * num. |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
61 |
* Solution 2 |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
62 |
#+begin_src python |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
63 |
print num if num%10 == 0 else 10*num |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
64 |
#+end_src |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
65 |
* Summary |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
66 |
In this tutorial session we learnt |
437
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
67 |
|
438
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
68 |
+ What are conditional statements |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
69 |
+ if/else statement |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
70 |
+ if/elif/else statement |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
71 |
+ Ternary conditional statement - ~C if X else Y~ |
4523b2048663
Reviewed conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
437
diff
changeset
|
72 |
+ and the ~pass~ statement |
437
0840aa06d2e6
Parially cleaned up conditionals LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
315
diff
changeset
|
73 |
|
315
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
74 |
* Thank you! |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
75 |
#+begin_latex |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
76 |
\begin{block}{} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
77 |
\begin{center} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
78 |
This spoken tutorial has been produced by the |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
79 |
\textcolor{blue}{FOSSEE} team, which is funded by the |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
80 |
\end{center} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
81 |
\begin{center} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
82 |
\textcolor{blue}{National Mission on Education through \\ |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
83 |
Information \& Communication Technology \\ |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
84 |
MHRD, Govt. of India}. |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
85 |
\end{center} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
86 |
\end{block} |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
87 |
#+end_latex |
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
88 |
|
7944a4504769
Conditionals LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
89 |