Learn String Manipulation by Building a Cipher - Step 49

Tell us what’s happening:

I dont understand where im going wrong, I tried to only rename the variables but i stil dont understand

Your code so far


# User Editable Region

text = 'Hello Zaira'
shift = 3

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

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

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/120.0.0.0 Safari/537.36 OPR/106.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

Welcome to the forum @ali.hzra

Every instance of text and shift needs to be updated.
I placed asterisks around the first two instances.

The instructions are just asking you to change the variable names. As you code, you may find more meaningful names for code, so will need to change every instance of it to update the code.

Happy coding

Hello ali.hzra,

You forgot to change a few instances such as:

Also keep in mind you only need to change textand shift, other variables such as encrypted_text should stay the same.

I can see the following in your code twice, these shouldn’t be renamed.

Hey Teller, this is unfortunately incorrect. Only everything inside the function body needs to be adjusted to match the function signature.

It was mentioned that every instance of the two variables need updating

The questions says “Inside your function body, rename the text and shift variables to message and offset, respectively.” Hence you dont need to rename anything outside it.

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

this is what I have changed, and I didnt change the variables I wasn’t supposed to, but it still is showing an error message

Hi @ali.hzra

You seem to have changed a string. Please change it back.

New to Python @HungryBee , still trying to shake JS cobwebs.

1 Like

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').