不知道我的变量去了哪里,"missing positional arguments"
Can't tell where my variables went, "missing positional arguments"
几个月前我开始学习python,所以我仍然不知道很多术语。
此程序从文本文件中获取坐标并找出最接近用户输入的点。
坐标列为纬度、经度、城市名称
当然我很惊讶它找不到变量,但我更惊讶它找到了一个但没有找到其他变量。
如果有人能向我解释为什么找不到它们,我将不胜感激。
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)
这是我得到的错误。
cit_dist=calc_dist((lat1, lon1, lat2, lon2))
TypeError: calc_dist() missing 3 required positional arguments: 'lon1', 'lat2', and 'lon2'
cit_dist=calc_dist((lat1, lon1, lat2, lon2))
错误是因为您使用了双括号。 (lat1, lon1, lat2, lon2)
被视为单个元组。
几个月前我开始学习python,所以我仍然不知道很多术语。
此程序从文本文件中获取坐标并找出最接近用户输入的点。 坐标列为纬度、经度、城市名称
当然我很惊讶它找不到变量,但我更惊讶它找到了一个但没有找到其他变量。
如果有人能向我解释为什么找不到它们,我将不胜感激。
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)
这是我得到的错误。
cit_dist=calc_dist((lat1, lon1, lat2, lon2))
TypeError: calc_dist() missing 3 required positional arguments: 'lon1', 'lat2', and 'lon2'
cit_dist=calc_dist((lat1, lon1, lat2, lon2))
错误是因为您使用了双括号。 (lat1, lon1, lat2, lon2)
被视为单个元组。