Hi I am trying a simple cipher program that will shift letters by the value the user enters, however, when the word has the letter "z", then it will throw an error that index out of range. So, in order to solve this I tried the easy way which is duplicating the list, but I would like to use a better way to do it. I would like to check if the index is out of range then loop again through the list and perform the same task as shown in the code Thanks a lot!
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']
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 encrypt(plain_text, shift_amount):
cipher_word = ""
indexed_letter = len(alphabet)
for letter in plain_text:
position = alphabet.index(letter)
new_position = position + shift_amount
new_letter = alphabet[new_position]
cipher_word += new_letter
if new_position > len(alphabet):
for i in alphabet.index(i - 1)
#here where I get stuck
print(f"You new encrypted word is {cipher_word}")
encrypt(plain_text=text, shift_amount=shift)