28 |
28 |
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
30 % Title page |
30 % Title page |
31 \title[Basic Python]{Python: Quiz} |
31 \title[Basic Python]{Python: Quiz} |
32 |
32 |
33 \author[FOSSEE Team] {FOSSEE Authors} |
33 \author[FOSSEE Team] {FOSSEE} |
34 |
34 |
35 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
35 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
36 \date[] {11, October 2009\\Day 1, Session 0} |
36 \date[] {11, October 2009\\Day 2, Session 0} |
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
38 |
38 |
39 |
39 |
40 \begin{document} |
40 \begin{document} |
41 |
41 |
42 \begin{frame} |
42 \begin{frame} |
43 \titlepage |
43 \titlepage |
44 \end{frame} |
44 \end{frame} |
45 |
45 |
46 \begin{frame}{} |
46 \begin{frame}{} |
47 What is the biggest integer number that can be represented by Python? |
47 What is the largest integer value that can be represented by Python? |
48 \end{frame} |
48 \end{frame} |
49 |
49 |
50 \begin{frame}{} |
50 \begin{frame}{} |
51 What is the result of 17.0 / 2? |
51 What is the result of 17.0 / 2? |
52 \end{frame} |
52 \end{frame} |
75 print "You are correct!" |
75 print "You are correct!" |
76 \end{lstlisting} |
76 \end{lstlisting} |
77 \end{frame} |
77 \end{frame} |
78 |
78 |
79 \begin{frame}{} |
79 \begin{frame}{} |
80 What is the difference between print x and print x, ? |
80 What is the difference between \kwrd{print} \emph{x} and \kwrd{print} \emph{x,} ? |
81 \end{frame} |
81 \end{frame} |
82 |
82 |
83 \begin{frame}{} |
83 \begin{frame}{} |
84 A single line of CSV file should be separated into fields. What method would you use to achieve this? |
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? |
85 \end{frame} |
89 \end{frame} |
86 |
90 |
87 \begin{frame}{} |
91 \begin{frame}{} |
88 How many items can a function return? |
92 How many items can a function return? |
89 \end{frame} |
93 \end{frame} |
90 |
94 |
91 \begin{frame}{} |
95 \begin{frame}[fragile]{} |
92 If function returns more than one item/object what is the return type of the function? |
96 \begin{lstlisting} |
93 \end{frame} |
97 >>> a = [1, 2, 5, 9] |
94 |
98 >>> a[:-1] |
95 \begin{frame}{} |
99 \end{lstlisting} |
96 Given a list a, what will its slice a[:-1] evaluate to? |
100 What is the output? |
97 \end{frame} |
101 \end{frame} |
98 |
102 |
99 \begin{frame}{} |
103 \begin{frame}{} |
100 How do you get a slice of the list where the slice has only alternate elements? |
104 How do you get the alternate elements of a list? |
101 \end{frame} |
105 \end{frame} |
102 |
106 |
103 \begin{frame}{} |
107 \begin{frame}{} |
104 How do you combine 2 lists? |
108 How do you combine the two lists \emph{a} and \emph{b}? |
105 \end{frame} |
109 \end{frame} |
106 |
110 |
107 \begin{frame}{} |
111 \begin{frame}{} |
108 How do you find the presence of a given element in the list? |
112 How do you find the presence of an element \emph{x} in the list \emph{a}? |
109 \end{frame} |
113 \end{frame} |
110 |
114 |
111 \begin{frame}{} |
115 \begin{frame}[fragile]{} |
112 You are given a tuple a = (1, 2, 5, 7). What is the result of a[1] = 3? |
116 \begin{lstlisting} |
113 \end{frame} |
117 >>> a = (1, 2, 5, 7) |
114 |
118 >>> a[1] |
115 \begin{frame}{} |
119 \end{lstlisting} |
116 We use \kwrd{for} to loop through the elements of a list. What do we have to do if we want to iterate through the elements of a list as well as get the index of the elements of the list as we iterate through? |
120 What is the output? |
117 \end{frame} |
121 \end{frame} |
118 |
122 |
119 \begin{frame}{} |
123 \begin{frame}[fragile]{} |
120 What is the difference between import math and from math import *? |
124 \begin{lstlisting} |
121 \end{frame} |
125 for x in "abcd": |
122 |
126 print x |
123 \begin{frame}{} |
127 |
124 What can be the keys of a dictionary? |
128 a |
125 \end{frame} |
129 b |
126 |
130 c |
127 \begin{frame}{} |
131 d |
128 What happens when you try to access a key in the dictionary that does not exist? |
132 \end{lstlisting} |
129 \end{frame} |
133 How do you get the following output? |
130 |
134 \begin{lstlisting} |
131 \begin{frame}{} |
135 0 a |
132 How do you avoid such an exception? |
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? |
133 \end{frame} |
156 \end{frame} |
134 |
157 |
135 \begin{frame}{} |
158 \begin{frame}{} |
136 How do you obtain all the keys of the dictionary? |
159 How do you obtain all the keys of the dictionary? |
137 \pause |
160 \pause |
138 \\all the values? |
161 \\all the values? |
139 \end{frame} |
162 \end{frame} |
140 |
163 |
141 \begin{frame}{} |
164 \begin{frame}[fragile]{} |
142 What will the set contain when you create a set from a list containing duplicate elements? |
165 \begin{lstlisting} |
|
166 >>> set([1, 2, 8, 2, 13, 8, 9]) |
|
167 \end{lstlisting} |
|
168 What is the output? |
143 \end{frame} |
169 \end{frame} |
144 |
170 |
145 \end{document} |
171 \end{document} |
146 |
172 |
147 \begin{enumerate} |
173 \begin{enumerate} |