Learn String Manipulation by Building a Cipher - Step 75

Tell us what’s happening:

Why doesn’t this exact code work? I don’t know the exact problem.

Your code so far

def vigenere(message, key, direction):

# User Editable Region

    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    final_message = ''
    key_index = 0
    for char in message.lower():
        if char == ' ':
            final_message += char
        else:
            key_char = key[key_index % len(key)].lower()
            key_index += 1

            offset = alphabet.index(key_char)

            try:
                index = alphabet.index(char)
            except ValueError:
                final_message += char
                continue

            new_index = (index + offset * direction) % len(alphabet)
            final_message += alphabet[new_index]
    return final_message


# 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/138.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 75

Welcome to the forum @ryoosunwoong353

Here is a comparison of the original code and your code.

The code in blue is the original code, the code in red is your code.
The code in magenta is the overlap.

It looks like you made changes to the code which you were not asked to do.

Please reset the step to restore the seed code and try again.
Only make the changes that are asked.

Happy coding

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