Back to Freecodecamp

Step 37

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

latest1.4 KB
Original Source

--description--

Now, replace new_char with encrypted_text. Also, modify the print() call into print('char:', char, 'encrypted text:', encrypted_text) to reflect this change.

--hints--

You should replace new_char with encrypted_text inside your for loop.

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*alphabet\s*\[\s*new_index\s*\]/));
  }
})

You should turn your print() call into print('char:', char, 'encrypted text:', encrypted_text) inside your for loop.

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.isFalse(/print\s*\(\s*new_char\s*\)/.test(commentless_code));
    assert(block_body.match(/print\s*\(\s*("|')char:\1\s*,\s*char\s*,\s*("|')encrypted\stext:\2\s*,\s*encrypted_text\s*\)/));
  }
})

--seed--

--seed-contents--

py
--fcc-editable-region--
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''

for char in text.lower():
    index = alphabet.find(char)    
    new_index = index + shift
    new_char = alphabet[new_index]
    print('char:', char, 'new char:', new_char)
--fcc-editable-region--