Learn String Manipulation by Building a Cipher - Step 66

I stuck here because i believe there is no mistake and i have removed the two print()s and added the return.encrypted_text but it still says " You should remove the two print() calls from your function." PLease help

my 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/122.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 66

That’s because current code causes SyntaxError. Take a closer look at the line with return, there’s something not right in it.

1 Like

I dont see anything wrong. Its my first course coding.

Remove the dot and give it a space. If you do not understand why, please, mention it again.

removed

I did like this, the ‘return’ statement was moved outside the ‘for’ loop. This is because the function should return the encrypted text after all characters have been processed, not after the first character. And I took off the quotes, because we want the value of the ENCRYPTED_TEXT not the string.

Hi and welcome to the forum!

Please don’t post solution code here, thank you

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.