Learn String Manipulation by Building a Cipher - Step 67

Tell us what’s happening:

help, i dont understand what i need to do

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]
        def something():
            return 'encrypted_text'

# User Editable Region

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 67

You are returning a string called ‘encrypted_text’. There is no string in the instructions in the grey shaded area otherwise there would be quotes around it. What is encrypted_text? Have a look earlier on in your code.

here is my code

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\]

    def something():

        return ' '

Have a look at your code. Where is encrypted text in your code? What is it? What do you think the question is asking you to return?

im so sorry

im so stupid, i dont think i can get this

im so sorry

Don’t say that ! You don’t have to be sorry, this is totally all right ! Not undestanding is a part of learning !

1 Like

im so sorry
im really doesnt understand waht i need to do
im sorry :frowning:

No need to be sorry! We try to guide campers to try and work it out for themselves. You nearly had it right but because you put quotes around encrypted text you were returning a string. Start at the beginning - cut and paste line 7 of hte code into a post and tell me what it is. Then look at the question and see if you can work out what you need to return.

Hi @Neixjcb ,

Here is a picture of the starting code for Step #67 with my markup:

You correctly removed the print statements from the last two lines (crossed out in light green). So, that’s done.

Then you were asked to replace those with a return statement.

It looks like you were confused by the example in the instructions, which showed a return statement in the body of a function.

But you don’t need to create a new function definition because you are already writing code inside the body of a function (see the red arrow).

So all you need to do now is add the return statement along with what it is you want to return from the function. In this case, you will return encrypted_text because that is what this function sets out to do…encrypt some text.

I hope that helps.

Happy coding!

encrypted_text = ‘’
its mean encrypted text doesn’t exist?

if i understand right

text = ‘Hello Zaira’

custom_key = ‘python’

def vigenere(message, key):

its? 😢


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


or still not?

I meant what is it in Python. Here’s a clue:

You need to understand what they are and what they do.

Is encrypted_text the same?

The example gives you the syntax for a return statement, there’s no equals sign.

I said you were close originally but you put:

return 'encrypted_text'

which is a string. encryptyed_text is not a a string in your code.

im so sorry
im not sure that all make sense
im stupid
its beter to close this

Congrats, @Neixjcb !

This is correct!

Don’t give up.

As you can see from the example code, there is no equal in a return statement. Your issue is what you are returning. The example may be confusing you, but the example is returning a string ‘spam’ when the function is called. Here you need to return the variable encrypted_text so that it can return the information stored in the variable.

You are very close.

def foo():
    return 'spam'

its not correct

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

// running tests

  1. Your code raised an error before any tests could run. Please fix it and try again.
  2. Your code raised an error before any tests could run. Please fix it and try again.
    // tests completed

Oops. I’m sorry…need more coffee. :grinning_face_with_smiling_eyes:

There is no equal sign between return and the variable you are returning. An equal sign (assignment operator) would only be used if you are assigning a value to a variable.


I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Sorry for writing the code incorrectly and confusing you, sorry

Have you sorted it now?

sorry
still no

sorry, you don’t have to help
never mind