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