Back to Freecodecamp

Step 55

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

latest1.3 KB
Original Source

--description--

Currently, your code raises a TypeError, because the caesar function is defined with two parameters (message and offset), therefore it expects to be called with two arguments.

Calling caesar() without the required arguments stops the execution of the code.

Give message and offset values, by passing text and shift as arguments to the caesar function call.

--hints--

You should pass text and shift as the arguments to your function call by including them inside the parentheses. Don't forget to separate the arguments with a comma.

js
({
    test: () => assert(runPython(
        `_Node(_code).find_calls('caesar')[0].is_equivalent('caesar(text, shift)')`
    ))
})

--seed--

--seed-contents--

py
text = 'Hello Zaira'
shift = 3

def caesar(message, offset):
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

    for char in message.lower():
        if char == ' ':
            encrypted_text += char
        else:
            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
    print('plain text:', message)
    print('encrypted text:', encrypted_text)
--fcc-editable-region--
caesar()
--fcc-editable-region--