Learn String Manipulation by Building a Cipher - Step 60

Tell us what’s happening:

Describe your issue in detail here.

Hi team. I need some help with this step.

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

/* User Editable Region */

        else:        
            # Find the right key character to encode
            key_char = key[key_index % len(key)]
            key_index += 1
offset = 1
offset.index()

/* User Editable Region */

            index = alphabet.find(char)
            new_index = (index + offset) % len(alphabet)
            encrypted_text += alphabet[new_index]
    print('plain text:', message)
    print('encrypted text:', encrypted_text)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 60
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-60`Preformatted text`

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

else:        
            # Find the right key character to encode
            key_char = key[key_index % len(key)]
            key_index += 1

offset = key_char.index('alphabet')

what help do you need?

I need help with this code:

offset = key_char.index(‘alphabet’)

I am doing it wrong, but I don’t have the solution.

indentation is important in Python, you need to put that line at least inside the function

I indented in the def vigenere function. But I still have the same error

        else:        
            # Find the right key character to encode
            key_char = key[key_index % len(key)]
            key_index += 1

    offset = key_char.index('alphabet')

don’t you need to continue writing inside the else?

hi,
it took me a minute as well but i found the solution:

Mod Edit Solution Removed

** when you get stuck just follow what they say word by word

Excellent advice, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

To solve this, we need to read carefully, the function we must declare must go inside the ‘else’ statement from the previous step.

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