vendredi 13 août 2021

How to solve UnboundLocalError: local variable 'L1' referenced before assignment?

I want this program to terminate the program when the user types exit.

I keep getting UnboundLocalError: local variable 'L1' referenced before assignment.

while True:
    L1 == input('Enter length of span AB in metre:')
    if L1 == "exit".lower() or L1 == "EXIT".upper():
        exit()
    elif L1 == "restart".lower():
        restart()
    try:
        L1 = float(L1)
    except ValueError:
        print("invalid input, please enter valid number")
        continue
    else:
        break

Aucun commentaire:

Enregistrer un commentaire