Back to Freecodecamp

Step 52

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

latest978 B
Original Source

--description--

To execute, a function needs to be called (or invoked) by appending a pair of parentheses after its name, like this:

py
function_name()

At the end of your code, call your caesar function. Pay attention to the indentation.

--hints--

You should call your caesar function. Make sure to write the function call at the beginning of the line.

js
({ test: () => assert.match(code, /^caesar\s*\(\s*\)/m) })

--seed--

--seed-contents--

py

text = 'Hello Zaira'
shift = 3

def caesar():
    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('plain text:', text)
    print('encrypted text:', encrypted_text)

--fcc-editable-region--

--fcc-editable-region--