Could someone help me with this code? Currently it displays the error:
ValueError: Invalid conversion specification
I am unsure on how to solve it. Also, could you tell me how to properly format this code so that it looks more tidy and whether or not I did other things wrong or if other errors will appear?
For testing purposes if you want you could use the two sets of longitudes and latitudes:
Latitude: 17.935667
Longitude: -76.7875
and
Latitude: -34.945
Longitude: 138.530556
Here is my code:
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))
There is a syntax error in your formatting. You should remove )
from {2:.5f)}
:
print("{0:s} {1:.5f} - {2:.5f}".format(city1, x1, y1)),