Learn String Manipulation by Building a Cipher - Step 66

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

text = 'Hello Zaira'
custom_key = 'python'

def vigenere(message, key):
    key_index = 0
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''

    for char in message.lower():
    
        # Append space to the message
        if char == ' ':
            encrypted_text += char
        else:        
            # Find the right key character to encode
            key_char = key[key_index % len(key)]
            key_index += 1

# User Editable Region

            # Define the offset and the encrypted letter
            offset = alphabet.index(key_char)
            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
    return(encrypted_text)

# 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 66

What did I wrong? It says it should return encrypted_text which is exactly what I put in it.

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

You should not use parentheses. Also, leave a space after the return statement.

2 Likes

Thank you.
Feel like I am constantly overcomplicating this.

Don’t worry, it’s normal :slightly_smiling_face:

1 Like

Thank you maybe help with this too?

It is step 67.

I have not a clue what should I do.

text = ‘Hello Zaira’
custom_key = ‘python’

def vigenere(message, key):
key_index = 0
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
encrypted_text = ‘’

for char in message.lower():

    # Append space to the message
    if char == ' ':
        encrypted_text += char
    else:        
        # Find the right key character to encode
        key_char = key[key_index % len(key)]
        key_index += 1

        # Define the offset and the encrypted letter
        offset = alphabet.index(key_char)
        index = alphabet.find(char)
        new_index = (index + offset) % len(alphabet)
        encrypted_text += alphabet[new_index]

return encrypted_text

vigenere(text,custom_key)
encryption=return

Hello @Neurodivercat, you’re supposed to call the vigenere function in this step. To do so with arguments, you can refer to this page: Python Functions

After that, simply assign the result to encryption.

You cannot use return outside of a function. To store the value returned by a function in a variable you need to assign the function call to that variable.

What result?

This is the last two line of the code. Idk what should encryption’s value be

def vigenere(text, custom_key)
encryption=

This does not work because return is a keyword used inside functions to specify the value to be returned, it’s not a variable and there’s no “value” to it.

When you call the vignere function, encrypted_text is returned.
So the correct way to capture the returned value would be to assign encryption directly to the function you’re calling, vigenere(text,custom_key).

Yes I get that part now, but what should be the value of encryption variable?

Assign encryption directly to the function you’re calling, which is vigenere(text,custom_key) .

Directly how? I tried the += method but it did not work so I am utterly lost.

No need to use +=. Use simple assignment operator.

To assign a value to a variable, just use the assignment operator like @Dario_DC mentioned. This is the = symbol.

So this is what you should be doing: encryption = vigenere(text, custom_key)

If you try to use the addition assignment operator +=,
encryption += vigenere(text, custom_key) is essentially
encryption = encryption + vigenere(text, custom_key).
You can see that this does not make sense because encryption has never been assigned a value prior to this.