Python飞行距离和时间计算器

时间:2015-08-09 06:07:15

标签: python math calculator distance plane

有人可以帮我这个代码吗?目前它显示错误:

  

ValueError:转换规范无效

我不确定如何解决它。另外,你能告诉我如何正确格式化这段代码,使它看起来更整洁,是否我做错了其他错误或是否会出现其他错误?

如果您想要测试,可以使用两组经度和纬度:

Latitude: 17.935667
Longitude: -76.7875

Latitude: -34.945
Longitude: 138.530556

这是我的代码:

import math

radius = 6371.01

city1 = raw_input("First city: ")
x1 = float(input("First latitude: "))
y1 = float(input("First longitude: "))
city2 = raw_input("Second City: ")
x2 = float(input("Second latitude: "))
y2 = float(input("Second longitude: "))

def distance(radius, x1, x2, y1, y2):

    d = radius * math.acos(math.sin(x1)*math.sin(x2)+math.cos(x1)*math.cos(x2)*math.cos(abs(y1-y2)))
    return d

distance = distance(radius, x1, x2, y1, y2)

Blackbird = 3230
BombardierCRJ1000 = 870

tbird = distance/3230
tBombardierCRJ1000 = distance/870

cseconds = tBombardierCRJ1000 * 60 * 60 * 60
hctime = cseconds / 3600
cseconds -= 3600*hctime 
mctime = cseconds / 60

hseconds = tbird * 60 * 60 * 60
hhtime = hseconds / 3600
hseconds -= 3600*hhtime 
mhtime =  hseconds / 60

print("Commercial aircraft: Bombardier CRJ 1000 - 870 km/hr")
print("High-Speed aircraft: SR-71 Blackbird - 1354 km/hr")

print("Departure")
print("City            Latitude    Longitude")  
print("{0:s}          {1:.5f}  -  {2:.5f)}" .format(city1, x1, y1))     
print("---------------------------------------------------------------    -------")
print("Destination")
print("City            Latitude    Longitude   Distance Commercial     High-Speed")
print("                                        (km)     Time (h:m)     Time (h:m)")
print("{0:s}     {1:.5f}      {2:.5f}       {3:.2f}       {4:d}:{5:d}     {6:d}:{7:d}" .format(city2, x2,y2, distance, hctime,mctime, hhtime, mhtime))

1 个答案:

答案 0 :(得分:2)

格式化时出现语法错误。您应该从)删除{2:.5f)}

print("{0:s}          {1:.5f}  -  {2:.5f}".format(city1, x1, y1)),
相关问题