I am learning String Manipulation by Building a Cipher, I reached Step 68, and I have tried to solve it and I have spent more than 3 hours, but I could not solve it, so I gave up, please help me instead of resetting the lesson
Your code so far
text = 'Hello Zaira'
custom_key = 'python'
def vigenere(text , custom_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)
# User Editable Region
encrypted_text += alphabet[new_index]
return encrypted_key
encryption = vigenere(text, custom_key)
# 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/126.0.0.0 Safari/537.36
Challenge Information:
Learn String Manipulation by Building a Cipher - Step 68
Just FYI when you use the “reset” button it just resets the step you’re on, not the whole project. Feel free to use it whenever you need to.
What you’ve written is correct, but it’s not indented correctly. It’s indented to be part of the function but it needs to be outside/after the function.
Call your function
You would not call your function from inside the function. Well, you would if you want a recursive function, but not in this case.
passing text and custom_key as the arguments
These variables are created outside the function so that’s a clue that you want to be outside the function.
What you’ve written is correct, but it’s not indented correctly. Just remove the indentation so that it’s at the left, and no longer part of the function.
Indentation to define and call the function should look like this:
the best way that I recommend to type faster is to learn touch typing .
get the basic finger positions down then just start typing!
a good sites to practice typing is monkeytype.