jeudi 23 mai 2019

Why do I get the error "NameError: name 'kh' is not defined"

I'm receiving the input data using sys, there are 2 strings b and l, those will go to an if-statement and will assign a value to kh and other variables, but I keep getting an error about kh

The input looks like this:

# Data Input

# Latitude
lat = float(sys.argv[1])
# Longitude
lon = float(sys.argv[2])
# Frequency Band
b = str(sys.argv[3])
# Link Type
l = str(sys.argv[4])
# Elevation
hs = float(sys.argv[5])/1000

and the if-statement looks like this:

if b == 'C' and l == 'UL':
    f = 6
    kh = 0.0007056
    ah = 1.5900
    kv = 0.0004878
    av = 1.5728
    tao = 45
elif b == 'C' and l == 'DL':
    f = 4
    kh = 0.0001071
    ah = 1.6009
    kv = 0.0002461
    av = 1.2476
    tao = 45

k = (kh + kv + (kh - kv) * pow(cos(radians(lat)), 2) * cos(radians(2 * tao))) / 2
print('k = ', k)
a = (kh * ah + kv * av + (kh * ah - kv * av) * pow(cos(radians(lat)), 2) * cos (radians(2 * tao))) / (2 * k)
print('a = ', a)

I expect the values of k and a to be floats, but I get the following error:

Traceback (most recent call last):
  File "pluviobol.py", line 529, in <module>
    k = (kh + kv + (kh - kv) * pow(cos(radians(lat)), 2) * cos(radians(2 * tao))) / 2
NameError: name 'kh' is not defined

Why is this occuring and how can I resolve it?

Aucun commentaire:

Enregistrer un commentaire