Skip to content

Commit 5ef40b5

Browse files
committed
Change directions to include new directory structure for all problems and add distance between two points solution
1 parent 99c697c commit 5ef40b5

21 files changed

+84
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Numbers
4040

4141
**Alarm Clock** – A simple clock where it plays a sound after X number of minutes/seconds or at a particular time.
4242

43-
**Distance Between Two Cities** – Calculates the distance between two cities and allows the user to specify a unit of distance. This program may require finding coordinates for the cities like latitude and longitude.
43+
[**Distance Between Two Cities**](https://github.com/dansackett/Projects/blob/master/_numbers/distance.py) – Calculates the distance between two cities and allows the user to specify a unit of distance. This program may require finding coordinates for the cities like latitude and longitude.
4444

4545
[**Credit Card Validator**](https://github.com/dansackett/Projects/blob/master/_numbers/cc_validator.py) – Takes in a credit card number from a common credit card vendor (Visa, MasterCard, American Express, Discoverer) and validates it to make sure that it is a valid number (look into how credit cards use a checksum).
4646

_numbers/bin_dec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Call By
77
- python
8-
- from numbers.bin_dec import converter
8+
- from _numbers.bin_dec import converter
99
- converter()
1010
1111
"""

_numbers/calc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Call By
77
- python
8-
- from numbers.calc import calc
8+
- from _numbers.calc import calc
99
- calc()
1010
1111
"""

_numbers/cc_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
Call By
1515
- python
16-
- from numbers.cc_validator import validate
16+
- from _numbers.cc_validator import validate
1717
- validate()
1818
1919
"""

_numbers/change.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
Call By
1414
- python
15-
- from numbers.change import change
15+
- from _numbers.change import change
1616
- change()
1717
1818
"""

_numbers/distance.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
Distance Between Two Cities
3+
- Calculates the distance between two cities and allows the user to specify
4+
a unit of distance. This program may require finding coordinates for the
5+
cities like latitude and longitude.
6+
7+
This will require you to download the geopy module located here:
8+
- https://code.google.com/p/geopy/
9+
- pip install geopy
10+
11+
It uses the Haversine formula to find an approximate distance between the points.
12+
- http://en.wikipedia.org/wiki/Haversine_formula
13+
14+
Call By
15+
- python
16+
- from _numbers.distance import distance
17+
- distance()
18+
19+
"""
20+
from geopy import geocoders
21+
import math
22+
23+
24+
def distance():
25+
point1 = raw_input('Enter a city and state ex: \'Tampa, FL\': ')
26+
point2 = raw_input('Enter another city and state ex: \'Tampa, FL\': ')
27+
28+
# Convert the typed locations to coordinates
29+
try:
30+
g = geocoders.GoogleV3()
31+
place1, (lat1, lng1) = g.geocode(point1)
32+
place2, (lat2, lng2) = g.geocode(point2)
33+
34+
# Radians measurements for angles
35+
lat1 = math.radians(lat1)
36+
lat2 = math.radians(lat2)
37+
lng1 = math.radians(lng1)
38+
lng2 = math.radians(lng2)
39+
40+
# Haversine Formula
41+
a = (1 - math.cos((2 * (lat2 - lat1)) / 2.0)) / 2.0
42+
b = math.cos(lat1) * math.cos(lat2)
43+
c = (1 - math.cos((2 * (lng2 - lng1)) / 2.0)) / 2.0
44+
d = math.sqrt(abs(a + (b * c)))
45+
e = 2 * 6371 * math.asin(d)
46+
47+
while True:
48+
output = raw_input('What units would you like the distance in? (Miles = M, Kilometers = KM): ').lower()
49+
50+
if output not in ['m', 'km']:
51+
print 'Choose between K and M, please.'
52+
else:
53+
break
54+
55+
if output == 'km':
56+
print '\nThe distance between {} and {} is:'.format(place1, place2)
57+
print '{0:.2f} km'.format(e)
58+
else:
59+
miles = e * 0.621371192
60+
print '\nThe distance between {} and {} is:'.format(place1, place2)
61+
print '{0:.2f} miles'.format(miles)
62+
63+
except (ValueError, geocoders.base.GeocoderError):
64+
print 'We couldn\'t find one of those locations!'

_numbers/factorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Call By
88
- python
9-
- from numbers.factorial import factorial
9+
- from _numbers.factorial import factorial
1010
- factorial()
1111
1212
"""

_numbers/fib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Call By
77
- python
8-
- from numbers.fib import fib
8+
- from _numbers.fib import fib
99
- fib()
1010
1111
"""

_numbers/find_pi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
Call By
99
- python
10-
- from numbers.find_pi import find_pi
10+
- from _numbers.find_pi import find_pi
1111
- find_pi()
1212
1313
"""

_numbers/happy_numbers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
Call By
1212
- python
13-
- from numbers.happy_numbers import happy
13+
- from _numbers.happy_numbers import happy
1414
- happy()
1515
1616
"""

0 commit comments

Comments
 (0)