--- a/day1/exercise/aliquot.py Mon Mar 08 20:45:33 2010 +0530
+++ b/day1/exercise/aliquot.py Thu Mar 11 18:01:23 2010 +0530
@@ -1,5 +1,7 @@
-
def aliquot(n):
+ """returns the aliquot of a number which
+ is defined as the sum of all the proper
+ divisors of a number"""
sum = 1
i = 2
@@ -7,7 +9,7 @@
if n % i == 0:
sum += i + (n / i)
i += 1
- if n % i == 0: sum += i
+ if i*i == n: sum += i
return sum
n = int(raw_input('Enter a number? '))
--- a/day1/exercise/amicable.py Mon Mar 08 20:45:33 2010 +0530
+++ b/day1/exercise/amicable.py Thu Mar 11 18:01:23 2010 +0530
@@ -1,15 +1,8 @@
-def is_perfect_square(n):
- i = 1
- while i * i < n:
- i += 1
- return i * i == n, i
-
def aliquot(n):
sum = 1
i = 2
- is_ps, root = is_perfect_square(n)
- while i < root:
+ while i * i < n:
if n % i == 0:
sum += i + (n / i)
i += 1
--- a/day1/exercise/amicable_debug.py Mon Mar 08 20:45:33 2010 +0530
+++ b/day1/exercise/amicable_debug.py Thu Mar 11 18:01:23 2010 +0530
@@ -1,16 +1,20 @@
import math
def aliquot(n):
- sum = 0
- for i in range(1, math.sqrt(n)+1):
+ sum = 1
+ i = 2
+
+ while i * i < n:
if n % i == 0:
- sum += i + n/i
+ sum += i + (n / i)
+ i += 1
+ if i*i == n: sum += i
return sum
amicable = []
-for n in range(10000, 100000):
+for n in range(1000, 10000):
m = aliquot(n)
- if aliquot(m) == n:
+ if m > n and aliquot(m) == n:
amicable.append((m, n))
print amicable
--- a/day1/exercise/even_perfect_4a.py Mon Mar 08 20:45:33 2010 +0530
+++ b/day1/exercise/even_perfect_4a.py Thu Mar 11 18:01:23 2010 +0530
@@ -11,4 +11,4 @@
square = i * i
if all_digits_even(square):
print square
- i += 1
+ i += 2
--- a/day1/exercise/kwfreq.py Mon Mar 08 20:45:33 2010 +0530
+++ b/day1/exercise/kwfreq.py Thu Mar 11 18:01:23 2010 +0530
@@ -1,6 +1,3 @@
-import keyword
-f = open('amicable.py')
-
freq = {}
for line in f:
words = line.split()
--- a/day1/exercise/pytriads.py Mon Mar 08 20:45:33 2010 +0530
+++ b/day1/exercise/pytriads.py Thu Mar 11 18:01:23 2010 +0530
@@ -10,8 +10,8 @@
else:
return gcd(b, a%b)
-for a in range(3, 501):
- for b in range( a+1, 501, 2):
+for a in range(3, 101):
+ for b in range( a+1, 101, 2):
if gcd( a, b ) == 1:
is_ps, c = is_perfect_square((a * a) + (b * b))
if is_ps: print a, b, c
--- a/day1/exercise/word_frequencies.py Mon Mar 08 20:45:33 2010 +0530
+++ b/day1/exercise/word_frequencies.py Thu Mar 11 18:01:23 2010 +0530
@@ -1,11 +1,13 @@
-f = open('/home/madhu/pyprogs/pytriads.py')
+f = open('/home/vattam/Desktop/circulate/word-freq/holmes.txt')
freq = {}
for line in f:
words = line.split()
for word in words:
key = word.strip(',.!;?\'" ')
- value = freq.get(key, 1)
- freq[key] = value + 1
+ if key in freq:
+ freq[key] += 1
+ else:
+ freq[key] = 1
print freq
--- a/day2/day2quiz.tex Mon Mar 08 20:45:33 2010 +0530
+++ b/day2/day2quiz.tex Thu Mar 11 18:01:23 2010 +0530
@@ -57,6 +57,7 @@
\item Name:
\item University/College/Company:
\item Student/Teacher/Professional:
+ \item Field of interest/study:
\end{itemize}
\end{frame}
@@ -162,7 +163,7 @@
In []: a = (1, 2, 3)
In []: a[1] = 10
\end{lstlisting}
- What is the result?
+ What is the output?
\end{frame}
\begin{frame}[fragile]
@@ -183,4 +184,3 @@
\end{frame}
\end{document}
-
--- a/day2/session1.tex Mon Mar 08 20:45:33 2010 +0530
+++ b/day2/session1.tex Thu Mar 11 18:01:23 2010 +0530
@@ -379,7 +379,7 @@
--------------------------------------------
TypeError Traceback (most recent call last)
-/<ipython console> in <module>()
+<ipython console> in <module>()
TypeError: can`t multiply sequence by
non-int of type `str`
--- a/day2/session2.tex Mon Mar 08 20:45:33 2010 +0530
+++ b/day2/session2.tex Thu Mar 11 18:01:23 2010 +0530
@@ -153,9 +153,7 @@
\begin{block}{Documentation convention}
\begin{itemize}
\item \alert{Anything within \typ{[]} is optional}
- \begin{itemize}
- \item Nothing to do with Python.
- \end{itemize}
+ \item Nothing to do with Python.
\end{itemize}
\end{block}
\end{frame}
@@ -219,37 +217,37 @@
\begin{lstlisting}
num = [1, 2, 3, 4]
\end{lstlisting}
-\centerline{is a list}
+is a list
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Lists: methods}
\begin{lstlisting}
-In []: num = [1, 2, 3, 4]
+In []: num = [9, 8, 2, 3, 7]
-In []: num + [9, 10, 11]
-Out[]: [1, 2, 3, 4, 9, 10, 11]
+In []: num + [4, 5, 6]
+Out[]: [9, 8, 2, 3, 7, 4, 5, 6]
-In []: num.append([9, 10, 11])
+In []: num.append([4, 5, 6])
In []: num
-Out[]: [1, 2, 3, 4, [9, 10, 11]]
+Out[]: [9, 8, 2, 3, 7, [4, 5, 6]]
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Lists: methods}
\begin{lstlisting}
-In []: num = [1, 2, 3, 4]
+In []: num = [9, 8, 2, 3, 7]
-In []: num.extend([5, 6, 7])
+In []: num.extend([4, 5, 6])
In []: num
-Out[]: [1, 2, 3, 4, 5, 6, 7]
+Out[]: [9, 8, 2, 3, 7, 4, 5, 6]
In []: num.reverse()
In []: num
-Out[]: [7, 6, 5, 4, 3, 2, 1]
+Out[]: [6, 5, 4, 7, 3, 2, 8, 9]
In []: num.remove(6)
In []: num
@@ -294,17 +292,17 @@
\begin{frame}[fragile]
\frametitle{List containership}
-\emphbar{Recall \typ{num} is \typ{[1, 2, 3, 4]}}
+\emphbar{Recall \typ{num} is \typ{[9, 8, 2, 3, 7]}}
\begin{lstlisting}
In []: 4 in num
+Out[]: False
+
+In []: b = 8
+In []: b in num
Out[]: True
-In []: b = 15
-In []: b in num
+In []: b not in num
Out[]: False
-
-In []: b not in num
-Out[]: True
\end{lstlisting}
\end{frame}
@@ -387,7 +385,7 @@
\end{frame}
\begin{frame} {Problem Set 2.1: Problem 2.1.1}
-You are given date strings of the form ``29 Jul, 2009'', or ``4 January 2008''. In other words a number, a string and another number, with a comma sometimes separating the items.\\Write a function that takes such a string and returns a tuple (yyyy, mm, dd) where all three elements are ints.
+You are given date strings of the form ``29 Jul, 2009'', or ``4 January 2008''. In other words a number, a string and another number, with a comma sometimes separating the items.\\Write a program that takes such a string as input and prints a tuple (yyyy, mm, dd) where all three elements are ints.
\end{frame}
\subsection{Sets}
@@ -453,7 +451,6 @@
\frametitle{Problem 2.2.2}
Given a list of words, find all the anagrams in the list.
-\inctime{15}
\end{frame}
\section{Functions}
--- a/day2/session3.tex Mon Mar 08 20:45:33 2010 +0530
+++ b/day2/session3.tex Thu Mar 11 18:01:23 2010 +0530
@@ -256,6 +256,7 @@
\end{frame}
\begin{frame}[fragile]
+ \frametitle{Now what?}
\begin{lstlisting}
Traceback (most recent call last):
File "four_plot.py", line 1, in <module>