I started learning python a few months back, so i don't know alot of terms still.
This program fetches co-ordinates from a text file and finds out which point is closest to the user input. the co-ordinates are listed lat,lon,cityname
of course i'm suprised that it can't find the variables, but i'm even more suprised that it found one but not the others.
I would be greatful if someone could explain to me why it can't find them.
points=open_points.read()
text_length_unfilt=len(points)
text_lenth=text_length_unfilt/3
cit_point = points.split(",")
#importing all of the items from math now
from math import radians
from math import atan2
from math import cos
from math import sin
from math import sqrt
#this allows the user to imput two numbers, one for lat, one for lon.
lat1=float(input("What is the Latatude of your point in degrees? "))
lon1=float(input("That's great. Now in degrees, what is the Longitude? "))
#function to reduce clutter
def calc_dist(lat1,lon1,lat2,lon2):
#this part converts the degrees into radians for the equation
lon1 = radians(lon1)
lat1 = radians(lat1)
lon2 = radians(lon2)
lat2 = radians(lat2)
#here i'm just using the equation from the rubrik
a = sin((lat1 - lat2) / 2) ** 2 cos(lat1) * cos(lat2) * sin((lon1 - lon2) / 2) ** 2
c = 2 * atan2(sqrt(a), sqrt(1 - a))
distance = 3958.8 * c
return(distance)
and this is the error i get.
cit_dist=calc_dist((lat1, lon1, lat2, lon2))
TypeError: calc_dist() missing 3 required positional arguments: 'lon1', 'lat2', and 'lon2'
CodePudding user response:
cit_dist=calc_dist((lat1, lon1, lat2, lon2))
The error is because you are using double parentheses. (lat1, lon1, lat2, lon2)
is treated as a single tuple.