Back to Freecodecamp

Step 18

curriculum/challenges/english/blocks/workshop-caesar-cipher/6819c5c9faf2548e556163d5.md

latest1.1 KB
Original Source

--description--

As you recall from previous lessons, the not operator is a unary logical operator that negates an expression:

py
print(not True) # False
print(not False) # True

Use the not operator to fix the condition of the if statement so that your function returns Shift must be an integer value. when shift is not an integer.

--hints--

You should use the not operator to negate isinstance(shift, int) in your if statement.

js
({ test: () => assert(runPython(`_Node(_code).find_function("caesar").find_ifs()[0].find_conditions()[0].is_equivalent("not isinstance(shift, int)")`)) })

--seed--

--seed-contents--

py
def caesar(text, shift):

--fcc-editable-region--
    if isinstance(shift, int):
--fcc-editable-region--
        return 'Shift must be an integer value.'
    
    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)