40 lines
987 B
Python
40 lines
987 B
Python
import math
|
|
|
|
RADIUS = 3956.6
|
|
|
|
def give_intro():
|
|
pass
|
|
|
|
def find(file, target_zip):
|
|
for line in file:
|
|
zip, lat, lng, city = line.rstrip().split(" : ")
|
|
if zip == target_zip:
|
|
print(zip + ":", city)
|
|
return float(lat), float(lng)
|
|
return 0, 0
|
|
|
|
def show_matches(file, lat1, lng1, miles):
|
|
pass
|
|
|
|
def distance(lat1, lng1, lat2, lng2):
|
|
lat1 = math.radians(lat1)
|
|
lng1 = math.radians(lng1)
|
|
lat2 = math.radians(lat2)
|
|
lng2 = math.radians(lng2)
|
|
the_cos = math.sin(lat1) * math.sin(lat2) \
|
|
+ math.cos(lat1) * math.cos(lat2) * math.cos(lng1 - lng2)
|
|
arc_length = math.acos(the_cos)
|
|
return arc_length * RADIUS
|
|
|
|
def main():
|
|
give_intro()
|
|
zip = input("What zip code are you interested in? ")
|
|
miles = float(input("And what proximity (in miles)? "))
|
|
print()
|
|
with open("zipcode.txt") as file:
|
|
lat, lng = find(file, zip)
|
|
file.seek(0)
|
|
show_matches(file, lat, lng, miles)
|
|
|
|
main()
|