Learn String Manipulation by Building a Cipher - Step 53

Tell us what’s happening:

Can anyone please help me.

Your code so far



# User Editable Region

def caesar(message, offset):
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''
    for char in text.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)
    message = 'Hello Zaira'
    offset = 3
caesar()

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 53

Please edit your post to Tell us what’s happening in your own words.
Learning to describe problems is hard, but it is an important part of learning how to code.
Also, the more you say, the more we can help!

Welcome to the forum @OlwethuL

The instructions asked you rename the variable names in the body of the function.

You renamed two variables outside the scope of the function, then placed them inside the function, which the instructions did not ask you to do.

Please reset the step to restore the original code.

Also, you missed one instance of text

Happy coding

Originally you had this code:

def caesar(message, offset):
    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)

The request says:

Inside your function body, rename the text and shift variables to message and offset, respectively.

You must concentrate only inside the function ceasar(), specifically in this statement:

new_index = (index + shift) % len(alphabet)

…because it has the variable shift, and in this statement

 print('plain text:', text)

…because it uses the variable text. As the task is asking, you have to substitute those variables with what it is asking, respectively.