Back to Freecodecamp

Step 17

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

latest1.1 KB
Original Source

--description--

The isinstance() function returns True if its first argument is an instance of the second argument, and False otherwise:

py
print(isinstance('Hello World', str)) # True
print(isinstance(42, int)) # True

Replace the current condition of your if statement with an isinstance() call. Pass in shift as the first argument, and int as the second argument.

--hints--

Your if statement should use isinstance(shift, int) as its condition.

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

--seed--

--seed-contents--

py
def caesar(text, shift):

--fcc-editable-region--
    if True:
--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)