Back to Freecodecamp

Step 54

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/6553f3fc92741c2bf8ded140.md

latest1.1 KB
Original Source

--description--

Inside your function body, rename the text and shift variables to message and offset, respectively.

--hints--

You should rename all occurrences of text to message.

js
assert.match(code, /for\s+char\s+in\s+message\.lower\s*\(\s*\)\s*:/);
assert.match(code, /print\s*\(\s*("|')(plain text|(plain )?message):\1\s*,\s*message\s*\)/);

You should rename shift to offset.

js
assert.match(code, /new_index\s*=\s*\(\s*index\s*\+\s*offset\s*\)\s*%\s*len\s*\(\s*alphabet\s*\)/);

--seed--

--seed-contents--

py
text = 'Hello Zaira'
shift = 3
--fcc-editable-region--
def caesar(message, offset):
    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)

caesar()
--fcc-editable-region--