2016-03-06 38 views
0
import math 

'''Parameters to input: NS, EW, degee, minute, second 
What the function does: converts bearing to azimuth 
Expected return value: azimuth''' 
def toAz(v,w,x,y,z): 
    if v == "W" and w == "S" and x >= 0 and x < 90: 
     azimuth = x,"deg",y,"min",z,"sec" 
    if v == "W" and w == "N" and x >= 90 and x < 180: 
     azimuth = (179-x),"deg",(60-y),"min",(60-z),"sec" 
    if v == "E" and w == "N" and x >= 180 and x < 270: 
     azimuth = (180+x),"deg",(y),"min",(z),"sec" 
    if v == "E" and w == "S" and x >= 270 and x < 360: 
     azimuth = (270+(89-x)),"deg",(60-y),"min",(60-z),"sec" 
    return azimuth 
+0

提示:如果所有的if子句都是「假」呢? –

回答

0

您需要在函數定義的頂部定義azimuth變量。因爲return azimuth預計azimuth變量存在於同一級別。

def toAz(v,w,x,y,z): 
    azimuth = None 
    if v == "W" and w == "S" and x >= 0 and x < 90: 
     azimuth = x,"deg",y,"min",z,"sec" 
    if v == "W" and w == "N" and x >= 90 and x < 180: 
     azimuth = (179-x),"deg",(60-y),"min",(60-z),"sec" 
    if v == "E" and w == "N" and x >= 180 and x < 270: 
     azimuth = (180+x),"deg",(y),"min",(z),"sec" 
    if v == "E" and w == "S" and x >= 270 and x < 360: 
     azimuth = (270+(89-x)),"deg",(60-y),"min",(60-z),"sec" 
    return azimuth 
相關問題