summaryrefslogtreecommitdiff
path: root/day1
diff options
context:
space:
mode:
authorChristopher Burns2010-06-27 22:05:22 -0500
committerChristopher Burns2010-06-27 22:05:22 -0500
commitf21d9dd7404db9415c11061de4a6792a322c413b (patch)
tree0b50a340405c3a1ac29325ad362f17d48451bde4 /day1
parent941b0d6900fb7a9cbc9c75c87c4807fbabbb0c83 (diff)
downloadworkshops-more-scipy-f21d9dd7404db9415c11061de4a6792a322c413b.tar.gz
workshops-more-scipy-f21d9dd7404db9415c11061de4a6792a322c413b.tar.bz2
workshops-more-scipy-f21d9dd7404db9415c11061de4a6792a322c413b.zip
REF: Reformat some of the exercises so they're easier to read for the audience.
--HG-- branch : scipy2010
Diffstat (limited to 'day1')
-rw-r--r--day1/exercise/arm.py8
-rw-r--r--day1/exercise/collatz.py12
-rw-r--r--day1/exercise/datestring.py26
3 files changed, 28 insertions, 18 deletions
diff --git a/day1/exercise/arm.py b/day1/exercise/arm.py
index 1234267..a1c2b64 100644
--- a/day1/exercise/arm.py
+++ b/day1/exercise/arm.py
@@ -3,8 +3,8 @@ for i in range(10):
cubes.append(i ** 3)
for i in range(100, 1000):
- a = i % 10
- b = (i / 10) % 10
- c = (i / 100) % 10
- if i == cubes[a] + cubes[b] + cubes[c]:
+ ones = i % 10
+ tens = (i / 10) % 10
+ hundreds = (i / 100) % 10
+ if i == cubes[ones] + cubes[tens] + cubes[hundreds]:
print "Armstrong Number: ", i
diff --git a/day1/exercise/collatz.py b/day1/exercise/collatz.py
index 3ace3ac..e270137 100644
--- a/day1/exercise/collatz.py
+++ b/day1/exercise/collatz.py
@@ -1,8 +1,8 @@
-a = int( raw_input( 'Enter number: ') )
-while a != 4:
- print a,
- if a % 2 == 1:
- a = a * 3 + 1
+num = int( raw_input( 'Enter number: ') )
+while num != 4:
+ print num,
+ if num % 2 == 1:
+ num = num * 3 + 1
else:
- a /= 2
+ num /= 2
print 4, 2, 1
diff --git a/day1/exercise/datestring.py b/day1/exercise/datestring.py
index 5a9c50f..e76c088 100644
--- a/day1/exercise/datestring.py
+++ b/day1/exercise/datestring.py
@@ -1,14 +1,24 @@
-month2mm = { 'JAN': 1, 'FEB': 2, 'MAR': 3, 'APR': 4, 'MAY': 5, 'JUN': 6,
-'JUL': 7, 'AUG': 8, 'SEP': 9, 'OCT': 10, 'NOV': 11, 'DEC': 12 }
+month2mm = {'JAN': 1,
+ 'FEB': 2,
+ 'MAR': 3,
+ 'APR': 4,
+ 'MAY': 5,
+ 'JUN': 6,
+ 'JUL': 7,
+ 'AUG': 8,
+ 'SEP': 9,
+ 'OCT': 10,
+ 'NOV': 11,
+ 'DEC': 12 }
COMMA = ','
SPACE = ' '
date_str = raw_input('Enter a date string? ')
-date_str = date_str.replace( COMMA, SPACE)
-d, m, y = date_str.split()
-dd = int( d )
-mon = m[:3].upper()
+date_str = date_str.replace(COMMA, SPACE)
+day, month, year = date_str.split()
+dd = int(day)
+mon = month[:3].upper()
mm = month2mm[mon]
-yyyy = int( y )
+yyyy = int(year)
-print dd,mm, yyyy
+print dd, mm, yyyy