day1quiz1.tex
changeset 334 2214b5dba4d4
parent 332 f2ca851199d4
parent 306 57291186d598
child 343 adb85e126341
equal deleted inserted replaced
333:25b18b51be41 334:2214b5dba4d4
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2 % Tutorial slides on Python.
     2 % Quiz slides day 1 quiz 1
     3 %
     3 %
     4 % Author: FOSSEE <info at fossee  dot in>
     4 % Author: FOSSEE <info at fossee  dot in>
     5 % Copyright (c) 2005-2009, FOSSEE Team
     5 % Copyright (c) 2005-2009, FOSSEE Team
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     7 
     7 
    33 \setcounter{qno}{0}
    33 \setcounter{qno}{0}
    34 \newcommand{\incqno}{\addtocounter{qno}{1}{Question \theqno}}
    34 \newcommand{\incqno}{\addtocounter{qno}{1}{Question \theqno}}
    35 
    35 
    36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    37 % Title page
    37 % Title page
    38 \title[Basic Python]{Python: Quiz}
    38 \title[Basic Python]{Python for science and engineering: Day 1, Quiz 1}
    39 
    39 
    40 \author[FOSSEE Team] {FOSSEE}
    40 \author[FOSSEE Team] {FOSSEE}
    41 
    41 
    42 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    42 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    43 \date[] {14, December 2009\\Day 1, Quiz 1}
    43 \date[] {\today \\Day 1, Quiz 1}
    44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    45 
    45 
    46 
    46 
    47 \begin{document}
    47 \begin{document}
    48 
    48 
    52 
    52 
    53 \begin{frame}
    53 \begin{frame}
    54   \frametitle{Write your details...}
    54   \frametitle{Write your details...}
    55 On the top right hand corner please write down the following:
    55 On the top right hand corner please write down the following:
    56   \begin{itemize}
    56   \begin{itemize}
    57     \item  Name:
    57     \item Name:
    58     \item Affliation:
    58     \item University/College/Company:
    59     \item Occupation:
    59     \item Student/Teacher/Professional:
    60   \end{itemize}
    60   \end{itemize}
       
    61 \end{frame}
       
    62 
       
    63 \begin{frame}[fragile]
       
    64 \frametitle{\incqno }
       
    65 Describe the plot produced by the following:
       
    66 
       
    67 \begin{lstlisting}
       
    68 In []: x = linspace(0, 2*pi)
       
    69 In []: plot(x, cos(x), 'go')
       
    70 \end{lstlisting}
       
    71 \end{frame}
       
    72 
       
    73 \begin{frame}
       
    74 \frametitle{\incqno }
       
    75 How will you plot the previous graph with line width set to 3?  How will
       
    76 you set the $x$ and $y$ labels of the plot?
       
    77 \end{frame}
       
    78 
       
    79 \begin{frame}
       
    80 \frametitle{\incqno }
       
    81 How will you set the x and y axis limits so that the region of interest
       
    82 is in the rectangle $(0, -1.5)$ (left bottom coordinate) and $(2\pi,
       
    83 1.5)$ (right top coordinate)?
    61 \end{frame}
    84 \end{frame}
    62 
    85 
    63 \begin{frame}
    86 \begin{frame}
    64 \frametitle{\incqno }
    87 \frametitle{\incqno }
    65   A sample line from a Comma Separated Values (CSV) file:\\
    88   A sample line from a Comma Separated Values (CSV) file:\\
    66   \vspace*{0.2in}
    89   \vspace*{0.2in}
    67   \emph{Rossum, Guido, 42, 56, 34, 54}\\
    90   \emph{Rossum, Guido, 42, 56, 34, 54}\\
    68   \vspace*{0.2in}
    91   \vspace*{0.2in}
    69   What method would you use to separate the line into fields?
    92   What code would you use to separate the line into fields?
    70 \end{frame}
    93 \end{frame}
    71 
    94 
    72 \begin{frame}[fragile]
    95 \begin{frame}[fragile]
    73 \frametitle{\incqno }
    96 \frametitle{\incqno }
    74   \begin{lstlisting}
    97   \begin{lstlisting}
    75   In [1]: a = [1, 2, 5, 9]
    98   In []: a = [1, 2, 5, 9]
    76   In [2]: a[:-1]
    99   In []: a[0:-1]
    77   \end{lstlisting}
   100   \end{lstlisting}
    78   What is the output?
   101   What is the output?
    79 \end{frame}
   102 \end{frame}
    80 
   103 
    81 \begin{frame}
   104 \begin{frame}
    82 \frametitle{\incqno }
   105 \frametitle{\incqno }
    83   How do you combine the two lists \emph{a} and \emph{b}?
   106   How do you combine two lists \emph{a} and \emph{b} to produce one list?
       
   107 \end{frame}
       
   108 
       
   109 \begin{frame}[fragile]
       
   110 \frametitle{\incqno }
       
   111   \begin{lstlisting}
       
   112   In []: a = [1, 2, 5, 9]
       
   113   \end{lstlisting}
       
   114   How do you add the value 10 to the end of this list?
       
   115 \end{frame}
       
   116 
       
   117 \begin{frame}[fragile]
       
   118 \frametitle{\incqno }
       
   119   \begin{lstlisting}
       
   120   In []: a = [1, 2, 5, 9]
       
   121   \end{lstlisting}
       
   122   How do you find the length of this list?
    84 \end{frame}
   123 \end{frame}
    85 
   124 
    86 \begin{frame}[fragile]
   125 \begin{frame}[fragile]
    87 \frametitle{\incqno }
   126 \frametitle{\incqno }
    88   \begin{lstlisting}
   127   \begin{lstlisting}
    93   In [2]: print d['c']
   132   In [2]: print d['c']
    94   \end{lstlisting}
   133   \end{lstlisting}
    95   What is the output?
   134   What is the output?
    96 \end{frame}
   135 \end{frame}
    97 
   136 
    98 \begin{frame}[fragile]
   137 %% \begin{frame}[fragile]
    99 \frametitle{\incqno }
   138 %% \frametitle{\incqno }
   100   \begin{lstlisting}
   139 %%   \begin{lstlisting}
   101   for x in "abcd":
   140 %%   for x in "abcd":
   102       print x
   141 %%       print x
   103 
   142 
   104   a
   143 %%   a
   105   b
   144 %%   b
   106   c
   145 %%   c
   107   d
   146 %%   d
   108   \end{lstlisting}
   147 %%   \end{lstlisting}
   109   How do you get the following output? 
   148 %%   How do you get the following output? 
   110   \begin{lstlisting}
   149 %%   \begin{lstlisting}
   111     0 a
   150 %%     0 a
   112     1 b
   151 %%     1 b
   113     2 c
   152 %%     2 c
   114     3 d
   153 %%     3 d
   115   \end{lstlisting}
   154 %%   \end{lstlisting}
   116 \end{frame}
   155 %% \end{frame}
   117 
   156 
   118 \begin{frame}
   157 \begin{frame}
   119 \frametitle{\incqno }
   158 \frametitle{\incqno }
   120 What ipython magic command do you use to obtain the lines of code you have already typed in the interpreter? What command do you use to save them?
   159 What ipython magic command do you use to obtain the lines of code you have already typed in the interpreter? What command do you use to save them?
   121 \end{frame}
   160 \end{frame}
   122 
   161 
   123 \begin{frame}
   162 \begin{frame}
   124 \frametitle{\incqno }
   163 \begin{lstlisting}
   125 How to read and print each line of a file?
   164 In []: sc = {'A': 10, 'B': 20, 
       
   165              'C': 70}
       
   166 \end{lstlisting}
       
   167 Given the above dictionary, what command will you give to plot a
       
   168 pie-chart?
       
   169 \end{frame}
       
   170 
       
   171 
       
   172 \begin{frame}[fragile]
       
   173 \frametitle{\incqno }
       
   174 \begin{lstlisting}
       
   175 In []: marks = [10, 20, 30, 50, 55, 
       
   176                 75, 83] 
       
   177 \end{lstlisting}
       
   178 
       
   179 Given the above marks, how will you calculate the \alert{mean} and
       
   180 \alert{standard deviation}?
       
   181 \end{frame}
       
   182 
       
   183 %\begin{frame}[fragile]
       
   184 %\frametitle{\incqno }
       
   185 %\begin{lstlisting}
       
   186 %In []: marks = [10, 20, 30, 50, 55, 
       
   187 %                75, 83] 
       
   188 %\end{lstlisting}
       
   189 %How will you convert the list \texttt{marks} to an \alert{array}?
       
   190 %\end{frame}
       
   191 
       
   192 %% \begin{frame}[fragile]
       
   193 %% \frametitle{\incqno }
       
   194 %% \begin{lstlisting}
       
   195 %% In []: a = array([[1, 2],
       
   196 %%                   [3, 4]])
       
   197 %% In []: a[1,0] = 0
       
   198 %% \end{lstlisting}
       
   199 %% What is the resulting matrix?
       
   200 %% \end{frame}
       
   201 
       
   202 %% \begin{frame}[fragile]
       
   203 %% \frametitle{\incqno }
       
   204 %% \begin{lstlisting}
       
   205 %% In []: a = array([[1, 2],
       
   206 %%                   [3, 4]])
       
   207 %% \end{lstlisting}
       
   208 %% How do you get the transpose of this array?
       
   209 %% \end{frame}
       
   210 
       
   211 %% \begin{frame}[fragile]
       
   212 %% \frametitle{\incqno }
       
   213 %% \begin{lstlisting}
       
   214 %% In []: a = array([[1, 2],
       
   215 %%                   [3, 4]])
       
   216 %% In []: b = array([[1, 1],
       
   217 %%                   [2, 2]])
       
   218 %% In []: a*b
       
   219 %% \end{lstlisting}
       
   220 %% What does this produce?
       
   221 %% \end{frame}
       
   222 
       
   223 %% \begin{frame}
       
   224 %% \frametitle{\incqno }
       
   225 %% What command do you use to find the inverse of a matrix and its
       
   226 %% eigenvalues?
       
   227 %% \end{frame}
       
   228 
       
   229 %% \begin{frame}
       
   230 %% \frametitle{\incqno }
       
   231 %% Given a 4x4 matrix \texttt{A} and a 4-vector \texttt{b}, what command do
       
   232 %% you use to solve for the equation \\
       
   233 %% \texttt{Ax = b}?
       
   234 %% \end{frame}
       
   235 
       
   236 \begin{frame}
       
   237 \frametitle{\incqno }
       
   238 Write the code to read a file \texttt{data.txt} and print each line of it?
   126 \end{frame}
   239 \end{frame}
   127 
   240 
   128 \begin{frame}[fragile]
   241 \begin{frame}[fragile]
   129 \frametitle{\incqno }
   242 \frametitle{\incqno }
   130 What is the output of:
   243 What is the output of: