Back to Freecodecamp

Step 47

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

latest1.2 KB
Original Source

--description--

Next, modify your print() call to print 'encrypted text:', encrypted_text and put it outside the for loop, so that the encrypted string is printed one time.

--hints--

You should print 'encrypted text:', encrypted_text after your for loop.

js
({ test: () => assert.match(code, /^print\s*\(\s*("|')encrypted\stext:\1\s*,\s*encrypted_text\s*\)/m) })

You should not have print('char:', char, 'encrypted text:', encrypted_text) in your code.

js
({ test: () => {
    const commentless_code = __helpers.python.removeComments(code);
    assert.notMatch(commentless_code, /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 Zaira'
shift = 3
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('char:', char, 'encrypted text:', encrypted_text)
--fcc-editable-region--