Back to Freecodecamp

Step 42

curriculum/challenges/english/blocks/learn-string-manipulation-by-building-a-cipher/6553980e0527fa115c705646.md

latest1.2 KB
Original Source

--description--

Now, instead of printing 'space!', use the addition assignment operator to add the space (currently stored in char) to the current value of encrypted_text.

--hints--

You should not have print('space!') in your code.

js
const commentless_code = __helpers.python.removeComments(code);
assert.notMatch(commentless_code, /print\s*\(\s*("|')space!\1\s*\)/);

You should use the += operator to add char to the current value of encrypted_text inside your new if statement.

js
const commentless_code = __helpers.python.removeComments(code);    
const {block_body} = __helpers.python.getBlock(commentless_code, /if\s+char\s*==\s*("|')\s\3\s*/);
assert(block_body.match(/encrypted_text\s*\+=\s*char/));

Your code contains invalid syntax and/or invalid indentation.

js
({test: () => assert(true) })

--seed--

--seed-contents--

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

for char in text.lower():
    if char == ' ':
        print('space!')
    index = alphabet.find(char)
    new_index = index + shift
    encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)
--fcc-editable-region--