Back to Freecodecamp

Step 14

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

latest1.4 KB
Original Source

--description--

In previous lessons, you learned that the return statement is used to return a value from a function, so that you can use it elsewhere in your code:

py
def spam():
    return 'Spam!'

Remove the print(encrypted_text) call from your function. Then, delete the declaration of the encrypted_text variable and return directly text.translate(translation_table) from your function.

--hints--

You should not have print(encrypted_text) within the caesar function.

js
({ test: () => assert(runPython(`not _Node(_code).find_function("caesar").has_call("print(encrypted_text)")`)) })

You should not have an encrypted_text variable within the caesar function.

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

Your caesar function should return text.translate(translation_table).

js
({ test: () => assert(runPython(`_Node(_code).find_function("caesar").has_return("text.translate(translation_table)")`)) })

--seed--

--seed-contents--

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

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