Back to Freecodecamp

Step 38

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/6568c86dc9193000d11ca5e0.md

latest977 B
Original Source

--description--

Instead of assigning alphabet[new_index] to encrypted_text, assign the current value of encrypted_text plus alphabet[new_index] to this variable.

--hints--

You should assign encrypted_text + alphabet[new_index] to your encrypted_text variable.

js
({ test: () => {
    const commentless_code = __helpers.python.removeComments(code);
    const {block_body} = __helpers.python.getBlock(commentless_code, /for\s+char\s+in\s+text\.lower\s*\(\s*\)\s*/);
    assert(block_body.match(/encrypted_text\s*=\s*encrypted_text\s*\+\s*alphabet\s*\[\s*new_index\s*\]/));
  }
})

--seed--

--seed-contents--

py
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
--fcc-editable-region--
for char in text.lower():
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text = alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)
--fcc-editable-region--