Build a Caesar Cipher - Step 22 issue

Tell us what’s happening:

in step 22, I faced with this issue; I wrote,

if not encrypt:
shift = - shift
but it doesn’t accept it. what is wrong here?
can anybody help me?

Your code so far

def caesar(text, shift, encrypt=True):

    if not isinstance(shift, int):
        return 'Shift must be an integer value.'

    if shift < 1 or shift > 25:
        return 'Shift must be an integer between 1 and 25.'

    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    

# User Editable Region

if not encrypt:
    shift = - shift    

# User Editable Region

    
    shifted_alphabet = alphabet[shift:] + alphabet[:shift]
    translation_table = str.maketrans(alphabet + alphabet.upper(), shifted_alphabet + shifted_alphabet.upper())
    encrypted_text = text.translate(translation_table)
    return encrypted_text


encrypted_text = caesar('freeCodeCamp', 3)
print(encrypted_text)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Build a Caesar Cipher - Step 22

hello and welcome to fcc forum :slight_smile:

  • this code passes for me when im correctly indenting it

try indenting it correctly and try again, happy coding :slight_smile:

i had the same problem. the issue is where you inputting the code. There is a darker shade line towards the middle line of the function where the test wants you to input the code there directly. Also if that doesnt work, try encrypt == False rather than not encrypt

Screenshot 2026-01-13 103215