I get an UnboundLocalError: when using NaN in my if-statements. If I set NaN to 0 then the code works fine. However the code needs to work with NaN and not 0.
I've read most of the topics regarding UnboundLocalError: but I did't find what I was looking for.
import math
from math import nan as NaN
def interest(A, P, R, N):
    if R == NaN:
        val = (A/P)**(1/float(N))-1
    elif P == NaN:
        val = A/(1+R)**N
    elif A == NaN:
        val = P * (1 + R)**N
    elif N == NaN:
        val = (math.log(A)- math.log(P))/ math.log(1+R)
    return val
    print(interest(1000, 200, NaN, 5))