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 :(得分: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