Build a Caesar Cipher - Step 21

Tell us what’s happening:

Didn’t I make a new parameter named encrypt and I set it to true?

Your code so far


# User Editable Region

def caesar(text, shift):

def encrypt(name= 'true'):

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

    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 (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 21

Hi @Rc2025

Add a third parameter named encrypt to your function and give it a default value of True.

Please carefully read the instructions.

You are not asked to create a new function.

Happy coding

def caesar(text, shift, encrypt= ‘True’):
I did this above but it doesn’t work. THis is a third parameter named encrypt with default value of true?

Add a third parameter named encrypt to your function and give it a default value of True.

Notice that True is not in quotes which means it’s a Boolean value and not a string.

https://www.w3schools.com/python/python_booleans.asp

1 Like

Oh no. I can’t believe I didn’t notice that simple thing. I know the difference pretty well too.