Build a Caesar Cipher - Step 21

Tell us what’s happening:

Hi, I am stucked on Step 21. I don’t seem to know how to create this code.

Your code so far


# User Editable Region

def caesar(text, shift):

# User Editable Region

    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.'

    encrypt = True

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Caesar Cipher - Step 21

I could solve it

Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.