Caesar cipher program returns correct decoded message except for y and z

I wrote a program that asks the user to enter a string that they want to be encrypted and it passes to the encode function and then that gets passed over to the decode function that gives the user the original string that they input using Caesar Cipher.

when encrypting everything works fine its the decoding i can get a-x to decipher correctly regardless of upper or lower case unfortunately my y and z give me _ and ‘ respectively seems to be the amount that i rotate the string here is my code.

def main():
    """This is where the program takes place and calls functions to perform tasks"""
    plain_text = input("What would you like to encrypt?  ")
    cipher_key = int(input("What is your shift amount: "))
    if cipher_key > 26 or cipher_key < 0:
        print("Please Enter a valid number from 1-26.nStarting Program Over...")
        return main()
    print(input("Press ENTER to encrypt your message..."))
    encoded_message = encode(plain_text, cipher_key)
    print(encoded_message)
    decoded_message = decode(encoded_message, cipher_key)
    print(input("Press ENTER to decrypt your message..."))
    print(decoded_message)
    

def encode(message, key):
    """Passed user input and assigns it to encoded_message and returns that to main"""
    encoded_message = ""
    for char in message:
        if char.isalpha():
            cipher_value = ord(char) + key
            if char.islower() and cipher_value > ord("z"):
                cipher_value = cipher_value - 26
            if char.isupper() and cipher_value > ord("Z"):
                cipher_value -= 26
            encoded_message += chr(cipher_value)
        else:
            encoded_message += char
    return encoded_message

def decode(message, key):
    """Passed encoded_message to thi function to return the deciphered string to main"""
    decoded_message = ""
    for char in message:
        if char.isalpha():
            cipher_value = ord(char) - key
            if char.islower() and cipher_value > ord("z"):
                cipher_value = cipher_value - 26
            if char.isupper() and cipher_value > ord("Z"):
                cipher_value = cipher_value - 26
            decoded_message += chr(cipher_value)
        else:
            decoded_message += char
    return decoded_message
    
main()

when ran with y and z my out put is

What would you like to encrypt?  yzyz
What is your shift amount: 3
Press ENTER to encrypt your message...

bcbc
Press ENTER to decrypt your message...

_`_`

can yall please explain what im missing

Answer

Since in the case of a caesar cipher, decryption is the opposite operation of encoding so you need to change your symbols to reflect this change:

            if char.islower() and cipher_value < ord("a"):
                cipher_value = cipher_value + 26
            if char.isupper() and cipher_value < ord("A"):
                cipher_value = cipher_value + 26

You also need to change z -> a and Z -> A since we now need to check for values that are shifted less than a and A.