Skip to content

Commit

Permalink
Progress on 16.07
Browse files Browse the repository at this point in the history
  • Loading branch information
epequeno committed Mar 10, 2012
1 parent 232f810 commit f912cdb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
12 changes: 4 additions & 8 deletions ch14/14.05.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@
user_input = str(raw_input("Zip Code? "))

def is_len_valid(user_input):
if len(user_input) != 5:
return False
else:
return True
return len(user_input) == 5

def is_all_num(user_input):
flag = True
Expand All @@ -65,9 +62,6 @@ def is_all_num(user_input):
return flag
return flag

data = requests.get("http://www.uszip.com/zip/" + user_input).content
data_list = [line for line in data.splitlines()]

def is_query_valid(data):
return "<title>" in data_list[1]

Expand All @@ -82,5 +76,7 @@ def main():
city = re.findall(r'\<title\>Zip\ code\ for\ (.*?)\ -\ ', data)
population = re.findall(r'Population:\<\/b\>\<\/td\>\<td\>(.*?)\ \<span', data)
print "%s (%s) has a population of %s" % (city[0], user_input, population[0])


data = requests.get("http://www.uszip.com/zip/" + user_input).content
data_list = [line for line in data.splitlines()]
main()
6 changes: 3 additions & 3 deletions ch15/15.01.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Point(object):
point_one = Point()
point_two = Point()

point_one.x, point_one.y = 2.0, 3.0
point_two.x, point_two.y = 4.0, 6.0
point_one.x, point_one.y = 6.0, 1.0
point_two.x, point_two.y = 2.0, 6.0

def distance(p1, p2):
"""Returns the distance between two points in 2d space."""
Expand All @@ -22,4 +22,4 @@ def distance(p1, p2):

print "The distance between point one at (%g,%g)" % (point_one.x, point_one.y),
print "and point two at (%g,%g)" % (point_two.x, point_two.y),
print "is", distance(point_one, point_two)
print "is %.3f" % distance(point_one, point_two)
42 changes: 30 additions & 12 deletions ch16/16.07.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,41 @@

# Current Status: Incomplete

rules = {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}

class Date(object):
"""Representation of a date
attributes: month, day, year"""

date = Date()
date.month = 1
date.day = 1
date.month = 12
date.day = 31
date.year = 2012

def increment_date(date, increment):
if date.month in [1, 3, 5, 7, 8, 10, 12]:
days_in_month = 31
elif date.month == 2:
days_in_month = 28
else:
days_in_month = 30
new_date = days_in_month + date.day + increment
print days_in_month
def increment(date, inc):
while True:
days_left = rules[date.month] - date.day
if (date.year % 4 == 0) and (date.month == 2):
rules[date.month] = 29

# TODO: Make this a switch jeez
if inc < days_left:
date.day += inc
break
elif inc == 0:
date.day = rules[date.month]
break
elif inc < 0:
date.day = rules[date.month] + inc
break
else:
inc -= rules[date.month]
date.month += 1

if date.month > 12:
date.year += 1
date.month = 1

print date.month, date.day, date.year

increment_date(date, 30)
increment(date, 1)

0 comments on commit f912cdb

Please sign in to comment.