Back to Freecodecamp

Step 19

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

latest1.4 KB
Original Source

--description--

A negative or null shift should not be accepted by your function. Therefore, after your first if statement, create another if statement that checks if shift is less than 1 and returns the string Shift must be a positive integer.

--hints--

You should have a second if statement that checks if shift is less than 1.

js
({ test: () => runPython(`
_cond = _Node(_code).find_function("caesar").find_ifs()[1].find_conditions()[0]
_options = ["shift < 1", "1 > shift", "shift <= 0", "0 => shift"]
assert any(_cond.is_equivalent(option) for option in _options)
`) })

Your second if statement should return Shift must be a positive integer.

js
({ test: () => assert(runPython(`_Node(_code).find_function("caesar").find_ifs()[1].find_bodies()[0].has_return("'Shift must be a positive integer.'")`)) })

--seed--

--seed-contents--

py
def caesar(text, shift):
    if not isinstance(shift, int):
        return 'Shift must be an integer value.'
    
--fcc-editable-region--
    
--fcc-editable-region--

    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)