Build a Caesar Cipher - Step 23

Tell us what’s happening:

everything looks good i have called my functions correctly

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'

    if not encrypt:
        shift = - shift
    
    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


# User Editable Region

    def encrypt(text,shift):
      caesar(text,shift)
      return
    def decrypt(text,shift):
      caesar(text,shift,False)
      return

# User Editable Region


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

Challenge Information:

Build a Caesar Cipher - Step 23

Hi

Why have you added return statements at the end of each function? Were you asked to do this?

were you asked to create these functions inside the caesar function? double check the indentation

1 Like