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.
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 ' '
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.
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.
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?
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.
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.