alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n") text = input("Type your message:\n").lower() shift = int(input("Type the shift number:\n")) def caesar(direction, text, shift): cipher_text = "" for letter in text: if direction == "encode": position = alphabet.index(letter) new_position += position elif direction == "decode": position = alphabet.index(letter) new_position -= position cipher_text += alphabet[new_position] print(cipher_text) caesar(direction, text, shift) UnboundLocalError: local variable 'new_position' referenced before assignment been trying to understand the concept of global variables but just can't figure out why there's an error occur in this code anyone know why and how please?
new_position. Aa+=1meansa=a+a. Definenew_positionbefore the loopshiftfor