Learn String Manipulation by Building a Cipher - Step 63

Tell us what’s happening:

Describe your issue in detail here.

Hi team. I need help with the return value of the function. I tried to assign it to the variable. It returned an error.

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

            # 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 */

vigenere(text,custom_key)
    return encryption =  'text', 'custom_key'
          

    
       

/* 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 Edg/120.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 63

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.

Call your function passing text and custom_key as the arguments. Store the return value of the function call in a variable called encryption .

You have called the function correctly but perhaps the second part of the instruction is a little confusing. Calling the function generates a return value, so you just need to assign the function call to the new variable (i.e. in the form variable = function_call).

1 Like

Hello Brice,

You were very close!

So for a bit of context the return keyword is used inside a function to give you a variable back when you call the function.

For example

def give_int():
      return 5

means that whenever you run the give_int function you get 5 back.

Now to assign that to a variable you would do something like:

int_var = give_int()

Which would now be the same as int_var = 5.

So with that knowledge, you already have return encrypted_text in your vigenere function. Which means if you call it, you get the encrypted text. To now assign this to your variable you can use:

REDACTED BY MOD

I hope this helps, you got this! :blush:

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.

Thanks HungryBee for the explanation it help me understand the return function much better.

2 Likes

Hi there:

STEP 63

Call your function passing text and custom_key as the arguments. Store the return value of the function call in a variable called encryption .

vigenere(text,custom_key)
return encryption = ‘text’, ‘custom_key’

Can anyone help me with the solution to this exercise please? im stuck here! :frowning:

Hi, you’ll need to to open a new topic:

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.