我在这组代码中得到一个unbundLocalError

2024-09-27 21:28:12 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Tags: andtoimportinputreturnifmathsec
1条回答
网友
1楼 · 发布于 2024-09-27 21:28:12

您需要在函数定义的顶部定义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

相关问题 更多 >

    热门问题