Back to Freecodecamp

Step 51

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/666064e915eba7aa1de03f6b.md

latest846 B
Original Source

--description--

Now, fix the error by removing the line that tries to print the alphabet variable outside of the caesar function.

--hints--

You should remove the print(alphabet) line.

js
({ test: () => assert.isFalse(runPython(`_Node(_code).has_call("print(alphabet)")`)) })

--seed--

--seed-contents--

py

text = 'Hello Zaira'
shift = 3

def caesar():
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

    for char in text.lower():
        if char == ' ':
            encrypted_text += char
        else:
            index = alphabet.find(char)
            new_index = (index + shift) % len(alphabet)
            encrypted_text += alphabet[new_index]
    print('plain text:', text)
    print('encrypted text:', encrypted_text)

--fcc-editable-region--
print(alphabet)
--fcc-editable-region--