Learn String Manipulation by Building a Cipher - Step 65

Tell us what’s happening:

im on computing with python and at level 65 it told me to return encrypted_text and delete print statements but nothing semt to work even tho i did what i was told to

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/125.0.0.0 Safari/537.36 Edg/125.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 65

Should the return() be in the else block like this?

Try putting the return statement at the same indentation level as the print() that you removed, I think you were to replace those with the return(). Or try different indentation levels.

The return keyword is used at the end of a function to return a value and end the function call.

From your code, your return keyword is indented inside your else block which although syntactically correct but not what you want in this case. That is why you do not get any error.

You want to return encrypted_text after the entire iteration of the for-loop , not just the first time the else block executes as you currently have in your code. Indent your return statement to execute after the for-loop block like this:

– solution code removed –

The return statement should be outside the for-loop block but within the vigenere function block.

This was borderline since it was partly pseudo code, but please use a more generic example to explain indentation.

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.

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