Learn String Manipulation by Building a Cipher - Step 49

Tell us what’s happening:

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

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 + shift) % 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 49

Hello ssday,

You are supposed to only changed the text/shift variables inside the function. Not the 2 variables at the beginning. You also missed one shift variable.

still didn’t work
in console: "You should rename ‘text’ to ‘message’ "

Here’s my code, I made the replacements and it worked:

Redacted

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Can you share your updated code?

dude… you explain then

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

Inside the body of the function only. You want to call the function with the arguments that you defined at the beginning of the code. When you all the function:

caesar(message,offset)

message and offset have no value.

2 Likes

let me try and explain it to you properly.

firstly, you missed a concept. You can transfer the value of a variable by renaming it; for example, age=13 then if want to rename the variable you can just say years_on_earth=age which will transfer the value of age to the years_on_earth variable. Same in this situation, you want to rename text to message and shift to offset. But you are required to rename it inside the function that’s all. so you shouldn’t change the variables outside but just transfer the values inside the function.

Secondly, you should NOT change encrypted_text to ecrypted_message same with the ‘plain text’ string the only thing you should change is the shift and the text variables after transferring values.

Also it is very important to understand what every line in your code does.

This has nothing to do with what’s being asked in the instructions for this task. Assigning the value of a variable to another variable is not “renaming a variable”.

I appreciate you trying to help, but please try to be polite and humble, it goes a long way. Thanks!

1 Like

Agreed. :ok: [pkdvalis] Got it! Please rest assured, I won’t post the entire code. I will post hints and suggestions. I am a very ‘explicitly talkative’ person, therefore I tend to answer in full. I am also a very investigative person, I enjoy asking lot of questions just out of curiosity. I find it easier if it’s WYSIWYG but, yeah, you are right, I shouldn’t post spoilers because , I find puzzles and mystery mind-engaging, that way the solution is etched in memory.

1 Like

I found the solution.
I shouldn’t renamed “encrypted_text”

1 Like

Wow! Good to hear that. :clap: Happy coding :slightly_smiling_face:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.