#Computes and outputs travel time
#For a given speed and distance
#Written by Emele Lasaqa 10/10/19
location = input("Enter your location in longitude and latitude: ")
location= int(location)
distance = input("Enter your distance in miles: ")
distance = float(distance)
time = distance/speed
print("At", location, "location latitude location longitude, it will take")
print(time, "hours to travel", distance, "miles.")
input("\n\nPress the Enter ket to exit"
我正在构建一个代码,计算从一个位置到另一个位置的出租车费, 所需的距离。但是我一直收到这个错误!有人可以帮我吗?
**This is the OUTPUT**
Enter your location in longitude and latitude: 18.1489° S, 178.4474° E
Traceback (most recent call last):
File "C:/Users/acer/Desktop/Distance - location calculator.py", line 5, in <module>
location = input("Enter your location in longitude and latitude: ")
File "<string>", line 1
18.1489° S, 178.4474° E
^
SyntaxError: invalid syntax
>>>
答案 0 :(得分:1)
您的位置是一个字符串,因此无法将其转换为int。您似乎还是不使用它。您也不提供速度。 如果是这样,那就更有意义了:
speed = input("Enter your speed: ")
speed = int(speed)
distance = input("Enter your distance in miles: ")
distance = float(distance)
time = distance / speed # works in python 3, if not cast as float
print(f"At {speed} it will take")
print(f"{time} hours to travel {distance} miles.")
您的脚本中有一些错误: