Python 飞行距离和时间计算器

Python Flight Distance And Time Calculator

有人可以帮我处理这段代码吗?当前它显示错误:

ValueError: Invalid conversion specification

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

出于测试目的,如果您愿意,可以使用两组经度和纬度:

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))

您的格式存在语法错误。您应该从 {2:.5f)}:

中删除 )
print("{0:s}          {1:.5f}  -  {2:.5f}".format(city1, x1, y1)),