278
|
1 |
#+LaTeX_CLASS: beamer
|
|
2 |
#+LaTeX_CLASS_OPTIONS: [presentation]
|
|
3 |
#+BEAMER_FRAME_LEVEL: 1
|
|
4 |
|
|
5 |
#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
|
|
6 |
#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
|
|
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
|
|
8 |
|
|
9 |
#+LaTeX_CLASS: beamer
|
|
10 |
#+LaTeX_CLASS_OPTIONS: [presentation]
|
|
11 |
|
|
12 |
#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
|
|
13 |
#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
|
|
14 |
|
|
15 |
#+LaTeX_HEADER: \usepackage{listings}
|
|
16 |
|
|
17 |
#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
|
|
18 |
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
|
|
19 |
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
|
|
20 |
|
|
21 |
#+TITLE: Loops
|
|
22 |
#+AUTHOR: FOSSEE
|
|
23 |
#+EMAIL:
|
|
24 |
#+DATE:
|
|
25 |
|
|
26 |
#+DESCRIPTION:
|
|
27 |
#+KEYWORDS:
|
|
28 |
#+LANGUAGE: en
|
|
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
|
|
31 |
|
|
32 |
* Outline
|
|
33 |
- Loop while a condition is true.
|
|
34 |
- Iterate over a sequence
|
|
35 |
- Breaking out of loops.
|
|
36 |
- Skipping iterations.
|
|
37 |
* Question 1
|
|
38 |
Write a ~while~ loop to print the squares of all the even
|
|
39 |
numbers below 10.
|
|
40 |
* Solution 1
|
|
41 |
#+begin_src python
|
|
42 |
In []: i = 2
|
|
43 |
|
|
44 |
In []: while i<10:
|
|
45 |
....: print i*i
|
|
46 |
....: i += 2
|
|
47 |
#+end_src
|
|
48 |
* Question 2
|
|
49 |
Write a ~for~ loop to print the squares of all the even numbers
|
|
50 |
below 10.
|
|
51 |
* Solution 2
|
|
52 |
#+begin_src python
|
|
53 |
In []: for n in range(2, 10, 2):
|
|
54 |
....: print n*n
|
|
55 |
#+end_src
|
|
56 |
* Question 3
|
|
57 |
Using the ~continue~ keyword modify the ~for~ loop to print the
|
|
58 |
squares of even numbers below 10, to print the squares of only
|
|
59 |
multiples of 4. (Do not modify the range function call.)
|
|
60 |
* Solution 3
|
|
61 |
#+begin_src python
|
|
62 |
for n in range(2, 10, 2):
|
|
63 |
if n%4:
|
|
64 |
continue
|
|
65 |
print n*n
|
|
66 |
#+end_src
|
|
67 |
* Summary
|
|
68 |
You should now be able to --
|
|
69 |
- use the ~for~ loop
|
|
70 |
- use the ~while~ loop
|
|
71 |
- Use ~break~, ~continue~ and ~pass~ statements
|
|
72 |
* Thank you!
|
|
73 |
#+begin_latex
|
|
74 |
\begin{block}{}
|
|
75 |
\begin{center}
|
|
76 |
This spoken tutorial has been produced by the
|
|
77 |
\textcolor{blue}{FOSSEE} team, which is funded by the
|
|
78 |
\end{center}
|
|
79 |
\begin{center}
|
|
80 |
\textcolor{blue}{National Mission on Education through \\
|
|
81 |
Information \& Communication Technology \\
|
|
82 |
MHRD, Govt. of India}.
|
|
83 |
\end{center}
|
|
84 |
\end{block}
|
|
85 |
#+end_latex
|
|
86 |
|
|
87 |
|