Back to Freecodecamp

Step 44

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

latest903 B
Original Source

--description--

Try to assign the string 'Hello Zaira' to your text variable and see what happens in the terminal.

You'll see a string index out of range exception. Don't worry, you'll figure out how to fix it soon!

--hints--

You should have a text variable.

js
assert.match(code, /^text\s*=/m)

You should assign the string 'Hello Zaira' to your text variable.

js
assert.match(code, /^text\s*=\s*("|')Hello\sZaira\1/m)

--seed--

--seed-contents--

py
--fcc-editable-region--
text = 'Hello World'
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
        encrypted_text += alphabet[new_index]
    print('char:', char, 'encrypted text:', encrypted_text)
--fcc-editable-region--