day1/session3.tex
changeset 359 cb17c87b090e
parent 358 162e3e453920
child 366 ec4cb3ba7f09
equal deleted inserted replaced
358:162e3e453920 359:cb17c87b090e
   140 \end{frame}
   140 \end{frame}
   141 
   141 
   142 \begin{frame}[fragile]
   142 \begin{frame}[fragile]
   143   \frametitle{Acceleration due to gravity - ``g''\ldots}
   143   \frametitle{Acceleration due to gravity - ``g''\ldots}
   144   \begin{lstlisting}
   144   \begin{lstlisting}
   145 In []: G = []
   145 In []: g_list = []
   146 In []: for line in open('pendulum.txt'):
   146 In []: for line in open('pendulum.txt'):
   147   ....     point = line.split()
   147   ....     point = line.split()
   148   ....     l = float(point[0])
   148   ....     l = float(point[0])
   149   ....     t = float(point[1])
   149   ....     t = float(point[1])
   150   ....     g = 4 * pi * pi * l / (t * t)
   150   ....     g = 4 * pi * pi * l / (t * t)
   151   ....     G.append(g)
   151   ....     g_list.append(g)
   152   \end{lstlisting}
   152   \end{lstlisting}
   153 \end{frame}
   153 \end{frame}
   154 
   154 
   155 \begin{frame}
   155 \begin{frame}
   156   \frametitle{Computing mean ``g''}
   156   \frametitle{Computing mean ``g''}
   161 
   161 
   162 \begin{frame}[fragile]
   162 \begin{frame}[fragile]
   163   \frametitle{Mean ``g''}
   163   \frametitle{Mean ``g''}
   164   \begin{lstlisting}
   164   \begin{lstlisting}
   165 In []: total = 0
   165 In []: total = 0
   166 In []: for g in G:
   166 In []: for g in g_list:
   167  ....:     total += g
   167  ....:     total += g
   168  ....:
   168  ....:
   169 
   169 
   170 In []: g_mean = total / len(G)
   170 In []: g_mean = total / len(g_list)
   171 In []: print 'Mean: ', g_mean
   171 In []: print 'Mean: ', g_mean
   172   \end{lstlisting}
   172   \end{lstlisting}
   173 \end{frame}
   173 \end{frame}
   174 
   174 
   175 \begin{frame}[fragile]
   175 \begin{frame}[fragile]
   176   \frametitle{Mean ``g''}
   176   \frametitle{Mean ``g''}
   177   \begin{lstlisting}
   177   \begin{lstlisting}
   178 In []: g_mean = sum(G) / len(G)
   178 In []: g_mean = sum(g_list) / len(g_list)
   179 In []: print 'Mean: ', g_mean
   179 In []: print 'Mean: ', g_mean
   180   \end{lstlisting}
   180   \end{lstlisting}
   181 \end{frame}
   181 \end{frame}
   182 
   182 
   183 \begin{frame}[fragile]
   183 \begin{frame}[fragile]
   184   \frametitle{Mean ``g''}
   184   \frametitle{Mean ``g''}
   185   \begin{lstlisting}
   185   \begin{lstlisting}
   186 In []: g_mean = mean(G)
   186 In []: g_mean = mean(g_list)
   187 In []: print 'Mean: ', g_mean
   187 In []: print 'Mean: ', g_mean
   188   \end{lstlisting}
   188   \end{lstlisting}
   189   \inctime{10}
   189   \inctime{10}
   190 \end{frame}
   190 \end{frame}
   191 
   191 
   331   \frametitle{Building parsed data \ldots}
   331   \frametitle{Building parsed data \ldots}
   332   \begin{lstlisting}
   332   \begin{lstlisting}
   333 science = {}
   333 science = {}
   334 
   334 
   335 for record in open('sslc1.txt'):
   335 for record in open('sslc1.txt'):
   336     record = record.strip()
       
   337     fields = record.split(';')
   336     fields = record.split(';')
   338 
   337 
   339     region_code = fields[0].strip()
   338     region_code = fields[0].strip()
   340   \end{lstlisting}
   339   \end{lstlisting}
   341 \end{frame}
   340 \end{frame}
   394   \frametitle{Building data for statistics}
   393   \frametitle{Building data for statistics}
   395   \begin{lstlisting}
   394   \begin{lstlisting}
   396 math_scores = []
   395 math_scores = []
   397 
   396 
   398 for record in open('sslc1.txt'):
   397 for record in open('sslc1.txt'):
   399     record = record.strip()
       
   400     fields = record.split(';')
   398     fields = record.split(';')
   401 
   399 
   402     score_str = fields[5].strip()
   400     score_str = fields[5].strip()
   403     score = int(score_str) if \
   401     score = int(score_str) if \
   404       score_str != 'AA' else 0
   402       score_str != 'AA' else 0