1 \documentclass[a4paper,10pt]{book} |
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 % Title page |
|
31 \title[Basic Python]{Python: Quiz} |
|
32 |
|
33 \author[FOSSEE Team] {FOSSEE} |
|
34 |
|
35 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
|
36 \date[] {11, October 2009\\Day 2, Session 0} |
|
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2 |
38 |
3 |
39 |
4 \begin{document} |
40 \begin{document} |
5 Which version of Python were you using? |
41 |
6 List some key differences between IPython and Vanilla Python |
42 \begin{frame} |
7 What is the biggest integer number that can be represented by Python? |
43 \titlepage |
8 What is the result of 17.0 / 2? |
44 \end{frame} |
9 What does '*' * 40 produce? |
45 |
10 |
46 \begin{frame}{} |
|
47 What is the largest integer value that can be represented by Python? |
|
48 \end{frame} |
|
49 |
|
50 \begin{frame}{} |
|
51 What is the result of 17.0 / 2? |
|
52 \end{frame} |
|
53 |
|
54 \begin{frame}{} |
|
55 What does '*' * 40 produce? |
|
56 \end{frame} |
|
57 |
|
58 \begin{frame}{} |
|
59 Which of the following is not a type in Python? |
|
60 \begin{enumerate} |
|
61 \item int |
|
62 \item float |
|
63 \item char |
|
64 \item string |
|
65 \end{enumerate} |
|
66 \end{frame} |
|
67 |
|
68 \begin{frame}[fragile]{} |
|
69 What happens when we run this code? |
|
70 \begin{lstlisting} |
|
71 a = False |
|
72 b = True |
|
73 c = True |
|
74 if a and b or c: |
|
75 print "You are correct!" |
|
76 \end{lstlisting} |
|
77 \end{frame} |
|
78 |
|
79 \begin{frame}{} |
|
80 What is the difference between \kwrd{print} \emph{x} and \kwrd{print} \emph{x,} ? |
|
81 \end{frame} |
|
82 |
|
83 \begin{frame}{} |
|
84 A sample line from a Comma Separated Values (CSV) file:\\ |
|
85 \vspace*{0.2in} |
|
86 \emph{Rossum, Guido, 42, 56, 34, 54}\\ |
|
87 \vspace*{0.2in} |
|
88 What method would you use to separate the line into fields? |
|
89 \end{frame} |
|
90 |
|
91 \begin{frame}{} |
|
92 How many items can a function return? |
|
93 \end{frame} |
|
94 |
|
95 \begin{frame}[fragile]{} |
|
96 \begin{lstlisting} |
|
97 >>> a = [1, 2, 5, 9] |
|
98 >>> a[:-1] |
|
99 \end{lstlisting} |
|
100 What is the output? |
|
101 \end{frame} |
|
102 |
|
103 \begin{frame}{} |
|
104 How do you get the alternate elements of a list? |
|
105 \end{frame} |
|
106 |
|
107 \begin{frame}{} |
|
108 How do you combine the two lists \emph{a} and \emph{b}? |
|
109 \end{frame} |
|
110 |
|
111 \begin{frame}{} |
|
112 How do you find the presence of an element \emph{x} in the list \emph{a}? |
|
113 \end{frame} |
|
114 |
|
115 \begin{frame}[fragile]{} |
|
116 \begin{lstlisting} |
|
117 >>> a = (1, 2, 5, 7) |
|
118 >>> a[1] |
|
119 \end{lstlisting} |
|
120 What is the output? |
|
121 \end{frame} |
|
122 |
|
123 \begin{frame}[fragile]{} |
|
124 \begin{lstlisting} |
|
125 for x in "abcd": |
|
126 print x |
|
127 |
|
128 a |
|
129 b |
|
130 c |
|
131 d |
|
132 \end{lstlisting} |
|
133 How do you get the following output? |
|
134 \begin{lstlisting} |
|
135 0 a |
|
136 1 b |
|
137 2 c |
|
138 3 d |
|
139 \end{lstlisting} |
|
140 by doing a small modification in the same two lines of code above? |
|
141 \end{frame} |
|
142 |
|
143 \begin{frame}{} |
|
144 What can you use as the keys of a dictionary? |
|
145 \end{frame} |
|
146 |
|
147 \begin{frame}[fragile]{} |
|
148 \begin{lstlisting} |
|
149 >>> d = { |
|
150 'a': 1, |
|
151 'b': 2 |
|
152 } |
|
153 >>> print d['c'] |
|
154 \end{lstlisting} |
|
155 What is the output? |
|
156 \end{frame} |
|
157 |
|
158 \begin{frame}{} |
|
159 How do you obtain all the keys of the dictionary? |
|
160 \pause |
|
161 \\all the values? |
|
162 \end{frame} |
|
163 |
|
164 \begin{frame}[fragile]{} |
|
165 \begin{lstlisting} |
|
166 >>> set([1, 2, 8, 2, 13, 8, 9]) |
|
167 \end{lstlisting} |
|
168 What is the output? |
|
169 \end{frame} |
|
170 |
11 \end{document} |
171 \end{document} |
|
172 |
|
173 \begin{enumerate} |
|
174 \item Which version of Python were you using? |
|
175 \item List some key differences between IPython and Vanilla Python |
|
176 \item What is the biggest integer number that can be represented by Python? |
|
177 \item What is the result of 17.0 / 2? |
|
178 \item What does '*' * 40 produce? |
|
179 \item List all the basic types available in Python. |
|
180 \item What happens when we run this code? |
|
181 a = False |
|
182 b = True |
|
183 c = True |
|
184 if a and b or c: |
|
185 print ``You are correct!'' |
|
186 \item Select last 3 alternative elements in any given list. |
|
187 \item Give the difference between print x and print x, |
|
188 \item A single line of CSV file should be separated into fields. What method would you use to achieve this? |
|
189 \item How many items can a function return? |
|
190 \item If function returns more than one item/object what is the return type of the function? |
|
191 \item How do you document a function? |
|
192 \item Given a list l, what will its slice l[:-1] evaluate to? |
|
193 \item How do you get a slice of the list where the slice has only alternate elements? |
|
194 \item How do you add another list at the end of a given list? |
|
195 \item How do you find if a given element is present in the list or not? |
|
196 \item You are given a tuple a = (1, 2, 5, 7). What happens when you do a[1] = 3? |
|
197 \item We use for to loop through the list elements. What do we have to do if we want to iterate through the elements of the list as well as get the index of the elements of the list as we iterate through? |
|
198 \item What is the difference between import math and from math import *? |
|
199 \item List at least 5 Standard Library Modules. |
|
200 \item How do you create a Python module of your own? |
|
201 \item What can be the keys of a dictionary? |
|
202 \item What happens when you try to access a key in the dictionary that does not exist? |
|
203 \item How do you avoid such an exception? |
|
204 \item How do you obtain all the keys of the dictionary? |
|
205 \item How do you obtain all the values of the dictionary? |
|
206 \item What will the set contain when you create a set from a list containing duplicate elements? |
|
207 \item Name any 2 types of Exception. |
|
208 \item Whats are the 2 IPython command you use for debugging? |
|
209 \end{enumerate} |