Learn String Manipulation by Building a Cipher - Step 70

Tell us what’s happening:

Why is this code not working? Please help me solve it.

Your code so far


# User Editable Region

text = 'Hello Zaira'
custom_key = 'python'

def vigenere(message, key, direction):
    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
    
# print(encryption)
# User Editable Region


# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 70

you are asked to comment out, not delete, the last two lines

did you copy the code from somewhere? you have an extra # User Editable Region

I did not do it myself at first, but even if I added a comment line to the last two lines, it did not work, so I searched the internet and could not find it, so it remained like this.

please reset the step, try again, and show us the code written by you

I did this and the result is

it does look like you did not comment out the last two lines of code

What should I write to make it a comment line?

what did you use to create the new comments you added?

Now I understand, thank you.

1 Like