我该如何解决此错误代码,找不到错误的地方

时间:2019-05-03 20:00:28

标签: python-3.x

我似乎找不到此代码出了错的地方。我得到SyntaxError: invalid syntax代表似乎不错的一行。

我在print()的测试用例2上看到错误,我尝试在错误之前查找我是否搞砸了,什么也看不到。

from math import pi, asin, sin, cos, sqrt, fabs  #imports
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

def GetTrackVelocity(lats, longs, times, ptRange=(0, len(times))):     #set up
    if len(lats) !=len(longs) or len(lats) != len(times):
        return False;

    r = 6366.0   #earths radius 

    (start, end) = ptRange

    lats = lats[start: end+1]
    longs = longs[start: end+1]
    times = times[start: end+1]

    totalDistance = 0 #km
    TotalTime = 0 #days
    count = len(lats)
    for i in range(0, count-1):
        lat1 = lats[i]
        long1 = longs[i]
        lat2 = lats[i+1]
        long2 = longs[i+1]
        deltaT = times[i+1]-times[i]

        lat2 = lat2 * pi /100.0
        long2 = long2 *pi/100.0
        lat1 = lat1 * pi/100.0
        long1 = long1 * pi/100.0

        d = 2 * r * math.asin( sqrt( (math.sin((lat2-lat1)/2)**2)+ math.cos(lat1)*math.cos(lat2)*math.sin((long2-long1)/2)))
        totalDistance += fabs(d)
        totalTtime += deltaT

    return totalDistance, totalTime, totalDistance/totalTime

#test cases
#1
d,t,v = GetTrackVelocity([42.5, 42.7, 43.1], [-77.2, -77.3, -77.2], [0, 0.2, 0.4])
print("Distance={:.2f} km, time={:.2f} Day, velocity={:.2f} km/day".format (d, t, v))
#2
d,t,v = GetTrackStats([42.5,42.7,43.1], [-77.1,-77.3,-77.2], [0,0.2,0.4], ptRange=(0,1)
print("Distance={:.2f} km, time={:.2f} Day, velocity={:.2f} km/day".format (d, t, v))  #error??  
#3                    
d,t,v = GetTrackStats([42.5,42.7,43.1], [-77.1,-77.3,-77.2], [0,0.2,0.4], ptRange=(1,2))
print("Distance={:.2f} km, time={:.2f} Day, velocity={:.2f} km/day".format (d, t, v))

我希望能得出结果。

0 个答案:

没有答案