diff options
-rw-r--r-- | circulate/sslc_allreg.py | 2 | ||||
-rw-r--r-- | circulate/sslc_bug.py | 2 | ||||
-rw-r--r-- | circulate/sslc_science.py | 2 | ||||
-rw-r--r-- | day1/session2.tex | 6 | ||||
-rw-r--r-- | day1/session3.tex | 14 | ||||
-rwxr-xr-x | day1/session6.tex | 23 | ||||
-rw-r--r-- | day2/session1.tex | 38 |
7 files changed, 48 insertions, 39 deletions
diff --git a/circulate/sslc_allreg.py b/circulate/sslc_allreg.py index b93405a..16dc12f 100644 --- a/circulate/sslc_allreg.py +++ b/circulate/sslc_allreg.py @@ -2,7 +2,7 @@ scores = [[], [], [], [], []] ninety_percents = [{}, {}, {}, {}, {}] for record in open('sslc1.txt'): - record = record.strip() +# record = record.strip() fields = record.split(';') region_code = fields[0].strip() diff --git a/circulate/sslc_bug.py b/circulate/sslc_bug.py index b018cfa..d7be3cb 100644 --- a/circulate/sslc_bug.py +++ b/circulate/sslc_bug.py @@ -1,7 +1,7 @@ science = {} for record in open('sslc1.txt'): - record = record.strip() +# record = record.strip() fields = record.split(';') region_code = fields[0].strip() diff --git a/circulate/sslc_science.py b/circulate/sslc_science.py index 7f96128..83a52ae 100644 --- a/circulate/sslc_science.py +++ b/circulate/sslc_science.py @@ -1,7 +1,7 @@ science = {} for record in open('sslc1.txt'): - record = record.strip() +# record = record.strip() fields = record.split(';') region_code = fields[0].strip() diff --git a/day1/session2.tex b/day1/session2.tex index 54dbd37..13efd55 100644 --- a/day1/session2.tex +++ b/day1/session2.tex @@ -353,7 +353,7 @@ $ cat pendulum.txt \begin{frame}[fragile] \frametitle{Plotting from \typ{pendulum.txt}} -Open a new script and type the following: +Type the following in an editor. Save as \typ{pend\_pl.py} \begin{lstlisting} l = [] t = [] @@ -372,8 +372,8 @@ show() \begin{frame} \frametitle{Save and run} \begin{itemize} - \item Save as pendulum\_plot.py. - \item Run using \kwrd{\%run -i pendulum\_plot.py} + \item Save as \typ{pend\_pl.py} + \item Run using \kwrd{\%run -i pend\_pl.py} \end{itemize} \end{frame} diff --git a/day1/session3.tex b/day1/session3.tex index 567a12c..135bfc1 100644 --- a/day1/session3.tex +++ b/day1/session3.tex @@ -142,13 +142,13 @@ \begin{frame}[fragile] \frametitle{Acceleration due to gravity - ``g''\ldots} \begin{lstlisting} -In []: G = [] +In []: g_list = [] In []: for line in open('pendulum.txt'): .... point = line.split() .... l = float(point[0]) .... t = float(point[1]) .... g = 4 * pi * pi * l / (t * t) - .... G.append(g) + .... g_list.append(g) \end{lstlisting} \end{frame} @@ -163,11 +163,11 @@ In []: for line in open('pendulum.txt'): \frametitle{Mean ``g''} \begin{lstlisting} In []: total = 0 -In []: for g in G: +In []: for g in g_list: ....: total += g ....: -In []: g_mean = total / len(G) +In []: g_mean = total / len(g_list) In []: print 'Mean: ', g_mean \end{lstlisting} \end{frame} @@ -175,7 +175,7 @@ In []: print 'Mean: ', g_mean \begin{frame}[fragile] \frametitle{Mean ``g''} \begin{lstlisting} -In []: g_mean = sum(G) / len(G) +In []: g_mean = sum(g_list) / len(g_list) In []: print 'Mean: ', g_mean \end{lstlisting} \end{frame} @@ -183,7 +183,7 @@ In []: print 'Mean: ', g_mean \begin{frame}[fragile] \frametitle{Mean ``g''} \begin{lstlisting} -In []: g_mean = mean(G) +In []: g_mean = mean(g_list) In []: print 'Mean: ', g_mean \end{lstlisting} \inctime{10} @@ -333,7 +333,6 @@ science = {} science = {} for record in open('sslc1.txt'): - record = record.strip() fields = record.split(';') region_code = fields[0].strip() @@ -396,7 +395,6 @@ savefig('science.png') math_scores = [] for record in open('sslc1.txt'): - record = record.strip() fields = record.split(';') score_str = fields[5].strip() diff --git a/day1/session6.tex b/day1/session6.tex index 71afcd3..a5c1a2c 100755 --- a/day1/session6.tex +++ b/day1/session6.tex @@ -250,10 +250,16 @@ Find the root of $sin(x)+cos^2(x)$ nearest to $0$ \frametitle{\typ{fsolve}} Root of $sin(x)+cos^2(x)$ nearest to $0$ \begin{lstlisting} -In []: fsolve(sin(x)+cos(x)**2, 0) +In []: fsolve(sin(x)+cos(x)*cos(x), 0) NameError: name 'x' is not defined +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{\typ{fsolve}} +\begin{lstlisting} In []: x = linspace(-pi, pi) -In []: fsolve(sin(x)+cos(x)**2, 0) +In []: fsolve(sin(x)+cos(x)*cos(x), 0) \end{lstlisting} \begin{small} \alert{\typ{TypeError:}} @@ -266,7 +272,7 @@ In []: fsolve(sin(x)+cos(x)**2, 0) We have been using them all along. Now let's see how to define them. \begin{lstlisting} In []: def f(x): - return sin(x)+cos(x)**2 + return sin(x)+cos(x)*cos(x) \end{lstlisting} \begin{itemize} \item \typ{def} @@ -332,7 +338,8 @@ Out[]: -0.66623943249251527 \begin{lstlisting} In []: from scipy.integrate import odeint In []: def epid(y, t): - .... k, L = 0.00003, 25000 + .... k = 0.00003 + .... L = 25000 .... return k*y*(L-y) .... \end{lstlisting} @@ -382,8 +389,10 @@ We shall use the simple ODE of a simple pendulum. \end{itemize} \begin{lstlisting} In []: def pend_int(initial, t): - .... theta, omega = initial - .... g, L = 9.81, 0.2 + .... theta = initial[0] + .... omega = initial[1] + .... g = 9.81 + .... L = 0.2 .... f=[omega, -(g/L)*sin(theta)] .... return f .... @@ -397,7 +406,7 @@ In []: def pend_int(initial, t): \item \typ{initial} has the initial values \end{itemize} \begin{lstlisting} -In []: t = linspace(0, 10, 101) +In []: t = linspace(0, 20, 101) In []: initial = [10*2*pi/360, 0] \end{lstlisting} \end{frame} diff --git a/day2/session1.tex b/day2/session1.tex index 5c083f2..5885994 100644 --- a/day2/session1.tex +++ b/day2/session1.tex @@ -451,6 +451,9 @@ In []: a = "# Not a comment!" In []: a = raw_input() 5 +In []: a +Out[]: '5' + In []: a = raw_input('Enter a value: ') Enter a value: 5 \end{lstlisting} @@ -463,8 +466,8 @@ Enter a value: 5 \begin{frame}[fragile] \frametitle{Simple IO: Console output} \begin{itemize} - \item \texttt{print} is straight forward - \item Put the following code snippet in a file \emph{hello1.py} + \item \typ{print} is straight forward + \item Put the following code snippet in a file \typ{hello1.py} \end{itemize} \begin{lstlisting} print "Hello" @@ -479,7 +482,7 @@ World \begin{frame}[fragile] \frametitle{Simple IO: Console output \ldots} -Put the following code snippet in a file \emph{hello2.py} +Put the following code snippet in a file \typ{hello2.py} \begin{lstlisting} print "Hello", print "World" @@ -489,7 +492,7 @@ In []: %run -i hello2.py Hello World \end{lstlisting} -\emphbar{Note the distinction between \texttt{print x} and \texttt{print x,}} +\emphbar{Note the distinction between \typ{print x} and \typ{print x,}} \end{frame} \section{Control flow} @@ -497,7 +500,7 @@ Hello World \frametitle{Control flow constructs} \begin{itemize} \item \kwrd{if/elif/else}: branching - \item \kwrd{C if X else Y}: Ternary conditional operator + \item \kwrd{C if X else D}: Ternary conditional operator \item \kwrd{while}: looping \item \kwrd{for}: iterating \item \kwrd{break, continue}: modify loop @@ -508,20 +511,19 @@ Hello World \subsection{Basic Conditional flow} \begin{frame}[fragile] \frametitle{\typ{If...elif...else} example} +Type out the code below in an editor. \small \begin{lstlisting} -In []: x = int(raw_input("Enter an integer:")) - -In []: if x < 0: - ...: print 'Be positive!' - ...: elif x == 0: - ...: print 'Zero' - ...: elif x == 1: - ...: print 'Single' - ...: else: - ...: print 'More' - ...: - ...: +x = int(raw_input("Enter an integer:")) +if x < 0: + print 'Be positive!' +elif x == 0: + print 'Zero' +elif x == 1: + print 'Single' +else: + print 'More' + \end{lstlisting} \inctime{10} \end{frame} @@ -542,7 +544,7 @@ num = int(a) if a != 'Q' else 0 \item Data types: int, float, complex, boolean, string \item Operators: +, -, *, /, \%, **, +=, -=, *=, /=, >, <, <=, >=, ==, !=, a < b < c \item Simple IO: \kwrd{raw\_input} and \kwrd{print} - \item Conditional structures: \kwrd{if/elif/else},\\ \kwrd{C if X else Y} + \item Conditional structures: \kwrd{if/elif/else},\\ \kwrd{C if X else D} \end{itemize} \end{frame} |