Learn String Manipulation by Building a Cipher - Step 65

Tell us what’s happening:

The question asks me to return encrypted_text so I added
return ‘encrypted_text’
at the bottom, which is incorrect. I’m not sure what I am doing wrong. Do I need to define a variable or something?
PS. previous answers to the question include mentions of #comments and direction, but so far neither has appeared in my code at all. Is it possible that this code has been changed since the last post since it’s a beta version?

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
            # 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 65

does it ask to return the string "encrypted_text" or the value of the variable?

Does it ask to return it inside the loop?

Hello there.
Remember the encrypted_text is a variable, when calling it, you should not nest it in quotation marks, the browser will interpret it as a string. Call it without the quotation marks.

Also, your return statement should be in the same indentation as your for loop.

Oh! That did the trick, thank you so much!

the example return the string 'spam', yes. encrypted_text is not a string, and it doesn’t say to return a string

1 Like