Back to Freecodecamp

Step 12

curriculum/challenges/english/blocks/workshop-caesar-cipher/6818e9c7c8dc5694e8f64fc3.md

latest980 B
Original Source

--description--

Now, test the caesar function by calling it with the string freeCodeCamp and the number 3 as the arguments. Assign the function call to a variable named encrypted_text.

--hints--

You should have a variable named encrypted_text in the global scope.

js
({ test: () => assert(runPython(`_Node(_code).has_variable("encrypted_text")`)) })

You should assign caesar('freeCodeCamp', 3) to the encrypted_text variable.

js
({ test: () => assert(runPython(`_Node(_code).find_variable("encrypted_text").is_equivalent("encrypted_text = caesar('freeCodeCamp', 3)")`)) })

--seed--

--seed-contents--

py
def caesar(text, shift):
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    shifted_alphabet = alphabet[shift:] + alphabet[:shift]
    translation_table = str.maketrans(alphabet, shifted_alphabet)
    encrypted_text = text.translate(translation_table)
    print(encrypted_text)

--fcc-editable-region--

--fcc-editable-region--