Learn String Manipulation by Building a Cipher - Step 63

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

            # 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)
encryption = encrypted_text

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:120.0) Gecko/20100101 Firefox/120.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 63

Please 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!

Sorry I didn’t write any description.
The problema is that I don’t understand how to asign the ‘return’ value of the function to the variable ‘encryption’. Any hints?

Let’s see an example.

def square(a):
    return a*a

This simple function returns the square value of a. If we want to show the square number of 3, we can use

print(square(3))

Which will show 9 in the output. If you want to assign the return value of that square function to an other variable, let’s say answer, we use

answer=square(3)

So you know what to do now?

By the way, this is for course developers: I think for complete newbies, it may be confusing to ask them to assign the return value of a function to a variable without giving examples.

Thanks, that´s what I thought. I even tried coding:
‘encryption = vigenere(text, custom_key)’
several times before posting here, but there must had been a problem with the page as it didn´t return it as ok.
It did now. Thanks!!

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