Learn String Manipulation by Building a Cipher - Step 60

Tell us what’s happening:

i have error in function body actually i gave correct variable but it was not accepting me why i don’t know please help me decleare a variable

Your code so far


# User Editable Region

 
text = 'Hello Zaira'
custom_key = 'python'

def vigenere(message, key):
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    encrypted_text = ''
    key_index= 0
     
    for char in message.lower():
        if char == ' ':
            encrypted_text += char
        else:
            index = alphabet.find(char)
            if index == -1:
                encrypted_text += char
                continue
            key_char = key[key_index % len(key)].lower()
            offset = alphabet.find(key_char)
            new_index=(index + offset)%len(alphabet)
            encrypted_text+=alphabet[new_index]
            key_index +=1
    print('plain text:', message)
    print('encrypted text:', encrypted_text)
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/137.0.0.0 Safari/537.36

Challenge Information:

Learn String Manipulation by Building a Cipher - Step 60

Hi there, welcome to the community! :blush:

According to the lesson instructions:

At the beginning of your function body, declare a key_index variable and set it to zero.

It looks like your key_index variable is not placed correctly according to the lesson instructions. RRevisit the lesson carefully and check where it’s supposed to be declared.