vendredi 12 novembre 2021

In Python : 0 I'm using if-else condition in a function and try to use else: variable value out of condition in a formula

I'm using if-else condition in a function and try to use else: variable value out of condition in a formula. but I get this error. i tried to use return in if-else condition as well.

My code is this -

def Formula():
    if len(con_a) == 0:
        print("a : No Data Found")
    else:
        a = con_a.CLOSE
        print("a : ",a.iloc[0])
    if len(con_b) == 0:
        print("b : No Data Found")
    else:
        b = con_b.CLOSE
        print("b : ",b.iloc[0])
    if len(con_c) == 0:
        print("c : No Data Found")
    else:
        c = con_c.CLOSE
        print("c : ",c.iloc[0])
    formula = a - (2 * b) + c
    print(formula)
    return formula
Formula()

Error - enter image description here

Aucun commentaire:

Enregistrer un commentaire