Learn String Manipulation by Building a Cipher - Step 49

Tell us what’s happening:

I don’t understand what is wrong. The directions are not clear enough, IMO. I have read all of the other forum posts on this step, but I can’t figure out what is wrong with my code.

Your code so far


/* User Editable Region */

message = 'Hello Zaira'
offset = 3

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

    for char in message.lower():
        if char == ' ':
            encrypted_message += char
        else:
            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_message += alphabet[new_index]
    print('plain message:', message)
    print('encrypted message:', encrypted_message)

caesar()

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

It needs to be changed only in the function, and only variables - text in literal strings should remain as it was.

Are you saying that the first two lines of my code should not be changed?

Yes, and string text also doesn’t need to be changed. Only the relevant variable names inside of the function.

This is my code:

text = 'Hello Zaira'
shift = 3

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

    for char in message.lower():
        if char == ' ':
            encrypted_message += char
        else:
            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_message += alphabet[new_index]
    print('plain message:', message)
    print('encrypted message:', encrypted_message)

caesar()

I can’t undestrand the error:
Sorry, your code does not pass. Keep trying.
You should rename text to message.

@bertullipaola Please for convenience start your own thread.