|
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
2 % Tutorial slides on Python. |
|
3 % |
|
4 % Author: FOSSEE <info at fossee dot in> |
|
5 % Copyright (c) 2005-2009, FOSSEE Team |
|
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
7 |
|
8 |
|
9 \documentclass[14pt,compress]{beamer} |
|
10 |
|
11 \mode<presentation> |
|
12 { |
|
13 \useoutertheme{split} |
|
14 \setbeamercovered{transparent} |
|
15 } |
|
16 |
|
17 \definecolor{darkgreen}{rgb}{0,0.5,0} |
|
18 |
|
19 \usepackage{listings} |
|
20 \lstset{language=Python, |
|
21 basicstyle=\ttfamily\bfseries, |
|
22 commentstyle=\color{red}\itshape, |
|
23 stringstyle=\color{darkgreen}, |
|
24 showstringspaces=false, |
|
25 keywordstyle=\color{blue}\bfseries} |
|
26 |
|
27 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } |
|
28 |
|
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
30 % Macros |
|
31 |
|
32 \newcounter{qno} |
|
33 \setcounter{qno}{0} |
|
34 \newcommand{\incqno}{\addtocounter{qno}{1}{Question \theqno}} |
|
35 |
|
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
37 % Title page |
|
38 \title[Basic Python]{Python: Quiz} |
|
39 |
|
40 \author[FOSSEE Team] {FOSSEE} |
|
41 |
|
42 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
|
43 \date[] {31, October 2009\\Day 1, Quiz 1} |
|
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
45 |
|
46 |
|
47 \begin{document} |
|
48 |
|
49 \begin{frame} |
|
50 \titlepage |
|
51 \end{frame} |
|
52 |
|
53 \begin{frame} |
|
54 \frametitle{Write your details...} |
|
55 On the top right hand corner please write down the following: |
|
56 \begin{itemize} |
|
57 \item Name: |
|
58 \item Affliation: |
|
59 \item Occupation: |
|
60 \end{itemize} |
|
61 \end{frame} |
|
62 |
|
63 \begin{frame} |
|
64 \frametitle{\incqno } |
|
65 A sample line from a Comma Separated Values (CSV) file:\\ |
|
66 \vspace*{0.2in} |
|
67 \emph{Rossum, Guido, 42, 56, 34, 54}\\ |
|
68 \vspace*{0.2in} |
|
69 What method would you use to separate the line into fields? |
|
70 \end{frame} |
|
71 |
|
72 \begin{frame}[fragile] |
|
73 \frametitle{\incqno } |
|
74 \begin{lstlisting} |
|
75 In [1]: a = [1, 2, 5, 9] |
|
76 In [2]: a[:-1] |
|
77 \end{lstlisting} |
|
78 What is the output? |
|
79 \end{frame} |
|
80 |
|
81 \begin{frame} |
|
82 \frametitle{\incqno } |
|
83 How do you combine the two lists \emph{a} and \emph{b}? |
|
84 \end{frame} |
|
85 |
|
86 \begin{frame}[fragile] |
|
87 \frametitle{\incqno } |
|
88 \begin{lstlisting} |
|
89 In [1]: d = { |
|
90 'a': 1, |
|
91 'b': 2 |
|
92 } |
|
93 In [2]: print d['c'] |
|
94 \end{lstlisting} |
|
95 What is the output? |
|
96 \end{frame} |
|
97 |
|
98 \begin{frame}[fragile] |
|
99 \frametitle{\incqno } |
|
100 \begin{lstlisting} |
|
101 for x in "abcd": |
|
102 print x |
|
103 |
|
104 a |
|
105 b |
|
106 c |
|
107 d |
|
108 \end{lstlisting} |
|
109 How do you get the following output? |
|
110 \begin{lstlisting} |
|
111 0 a |
|
112 1 b |
|
113 2 c |
|
114 3 d |
|
115 \end{lstlisting} |
|
116 \end{frame} |
|
117 |
|
118 \begin{frame}[fragile] |
|
119 \frametitle{\incqno } |
|
120 What would be the result? |
|
121 \begin{lstlisting} |
|
122 In [1]: x |
|
123 array([[0, 1, 2], |
|
124 [3, 4, 5], |
|
125 [6, 7, 8]]) |
|
126 In [2]: x[::-1,:] |
|
127 \end{lstlisting} |
|
128 \end{frame} |
|
129 |
|
130 \begin{frame} |
|
131 \frametitle{\incqno } |
|
132 How to read and print each line of file. |
|
133 \end{frame} |
|
134 |
|
135 \begin{frame} |
|
136 \frametitle{\incqno } |
|
137 How to get list of third column of a data file. |
|
138 \end{frame} |
|
139 |
|
140 \begin{frame}[fragile] |
|
141 \frametitle{\incqno } |
|
142 What is the output of: |
|
143 \begin{lstlisting} |
|
144 In []: x=linspace(0 , 2 * pi) |
|
145 In []: plot(x, cos(x),'go') |
|
146 \end{lstlisting} |
|
147 \end{frame} |
|
148 |
|
149 \end{document} |
|
150 |